rfcs
rfcs copied to clipboard
Pipeline or Extension Methods?
I'm opening this issue as more of a question about which option would be best to go forward with. I see two options for improving the syntax for chaining together operations that are not methods on classes.
To show the differences between the two options here is a simple class that we want to work with:
// package a
class Foo[A]
fun foo[B](): Foo[B] => ...
fun bar() => ...
Option 1 would be to add something similar to the pipeline operator:
// package b
primitive Baz[A]
fun baz(foo: Foo[A]) => ...
actor Main
new create(env: Env) =>
Foo[A]
.foo[B]()
.> bar()
|> Baz[B].baz()
Option 2 is to allow extending a class, interface, or trait from outside of the package in which it is defined. These extensions would not have access to the private members of the type that they extend:
// package b
extention Foo[A]
fun baz() => ...
actor Main
new create(env: Env) =>
Foo[A]
.foo[B]()
.>bar()
.>baz()
The first option seems better to me unless we could extend an algebraic data type:
type Option[A] is (A | None)
extention Option[A]
fun map[B]({(A): B^}): Option[B] => ...
a |> f
// equivalent to
f(a)
b |2> f(a) // or b |1> f(a) if starting at 0
// equivalent to
f(a, b)
b |b_arg> f(a)
// equivalent to
f(a, where b_arg = b)