Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pipeline or Extension Methods? #89

Open
Theodus opened this issue Apr 1, 2017 · 1 comment
Open

Pipeline or Extension Methods? #89

Theodus opened this issue Apr 1, 2017 · 1 comment

Comments

@Theodus
Copy link
Contributor

Theodus commented Apr 1, 2017

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] => ...
@igotfr
Copy link

igotfr commented Jun 6, 2021

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants