grain icon indicating copy to clipboard operation
grain copied to clipboard

feat(compiler)!: Partial function application

Open alex-snezhko opened this issue 1 year ago • 2 comments

Partial function application

let add = (x, y) => x + y
let add1 = partial add(1, _)
assert add1(2) == 3

let printValues = (x, y, z=3) => {
  print(x)
  print(y)
  print(z)
}
let printSome = partial printValues(y=2, _, z=_)
printSome(1) // prints 1, 2, 3

Closes #402

alex-snezhko avatar Apr 07 '24 23:04 alex-snezhko

TODO:

  • [x] Make precedence of partial tighter to allow x |> partial add(_, y) without parentheses around the partial expression
  • [x] ~~Decide if this feature should be supported for infix functions~~ - doesn't seem particularly useful so will not do in this PR

alex-snezhko avatar Apr 08 '24 00:04 alex-snezhko

Marked this as breaking because of the new keywords.

ospencer avatar Apr 19 '24 21:04 ospencer