diff --git a/examples/partial_application.dry b/examples/partial_application.dry new file mode 100644 index 0000000..7413afa --- /dev/null +++ b/examples/partial_application.dry @@ -0,0 +1,16 @@ +let sum = lambda(x, y) { return x + y }; +let onePlus = sum(1, _); + +assert_equal("Supply first function arg only", onePlus(3), 4); +assert_equal("Supply second function arg only", sum(_, 3)(7), 10); + +class HasMinus { + def minus(x, y) { + return x - y; + } +} + +let tenMinus = HasMinus().minus(10, _); + +assert_equal("Supply first method arg only", tenMinus(6), 4); +assert_equal("Supply second method arg only", HasMinus().minus(_, 4)(15), 11); \ No newline at end of file diff --git a/src/main/scala/com/melvic/dry/parsers/ExprParser.scala b/src/main/scala/com/melvic/dry/parsers/ExprParser.scala index fd87134..91c883d 100644 --- a/src/main/scala/com/melvic/dry/parsers/ExprParser.scala +++ b/src/main/scala/com/melvic/dry/parsers/ExprParser.scala @@ -11,6 +11,7 @@ import com.melvic.dry.result.Failure.ParseError import scala.annotation.nowarn +//noinspection ScalaWeakerAccess private[parsers] trait ExprParser { _: Parser => def expression: ParseResult[Expr] = assignment diff --git a/src/main/scala/com/melvic/dry/parsers/StmtParser.scala b/src/main/scala/com/melvic/dry/parsers/StmtParser.scala index f88b774..dfc4dd1 100644 --- a/src/main/scala/com/melvic/dry/parsers/StmtParser.scala +++ b/src/main/scala/com/melvic/dry/parsers/StmtParser.scala @@ -9,6 +9,7 @@ import com.melvic.dry.ast.Stmt.Loop.While import com.melvic.dry.ast.Stmt.{BlockStmt, ExprStmt, Import, ReturnStmt} import com.melvic.dry.ast.{Decl, Expr, Stmt} +//noinspection ScalaWeakerAccess private[parsers] trait StmtParser { _: Parser with DeclParser => def statement: ParseResult[Stmt] = select( diff --git a/tests/test_calls.dry b/tests/test_calls.dry index ade02f1..bc8371f 100644 --- a/tests/test_calls.dry +++ b/tests/test_calls.dry @@ -1,9 +1,23 @@ -def test_partial_application() { +def test_function_partial_application() { let sum = lambda(x, y) { return x + y }; let onePlus = sum(1, _); - assert_equal("Supply first param only", onePlus(3), 4); - assert_equal("Supply second param only", sum(_, 3)(7), 10); + assert_equal("Supply first function arg only", onePlus(3), 4); + assert_equal("Supply second function arg only", sum(_, 3)(7), 10); } -test_partial_application(); \ No newline at end of file +def test_method_partial_application() { + class HasMinus { + def minus(x, y) { + return x - y; + } + } + + let tenMinus = HasMinus().minus(10, _); + + assert_equal("Supply first method arg only", tenMinus(6), 4); + assert_equal("Supply second method arg only", HasMinus().minus(_, 4)(15), 11); +} + +test_function_partial_application(); +test_method_partial_application();