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

Pipes #13

Open
chronium opened this issue Oct 30, 2019 · 2 comments
Open

Pipes #13

chronium opened this issue Oct 30, 2019 · 2 comments
Labels
enhancement New feature or request
Milestone

Comments

@chronium
Copy link
Owner

An idea from @SplittyDev was implementing pipes. similar to F# piping. Useful for method chaining in a functional way, and creating partially applied functions.

fn toInt str -> i128 // transforms from srt to i128

"42" |> toInt
// and the reverse would be
toInt <| "42"

// equivalent to
toInt "42"

That was example syntax, the use case is not the most appliable, but the syntax is what it shows.

@chronium chronium added this to the Alpha v0.2 milestone Oct 30, 2019
@chronium chronium added the enhancement New feature or request label Oct 30, 2019
@SplittyDev
Copy link
Collaborator

SplittyDev commented Oct 30, 2019

This can be especially useful if there is a big chain of functions:

getRandomString |> xorWith (_, "very secret key") |> toSha256Bytes |> toHex

Otherwise, this would be:

toHex (toSha256Bytes (xorWith (getRandomString(), "very secret key")))

One question is how the semantics should be with multiple parameters.

Consider the following setup:

extern fn add (a: i32, b: i32) -> i32

@entry
fn main () -> () = {
	val a = 2
	val b = 4
	...
}

If we fill from left:

a |> add b // add(a, b)

If we fill from right:

a |> add b // add(b, a)

If we let the user specify the entry point:

a |> add (_, b) // add(a, b)
a |> add (b, _) // add (b, a)

I think the standard semantics of the backwards pipe is to fill from right:

foo a <| b // foo (a, b)

So I guess the semantics of the forwards pipe should be to fill from left:

a |> foo b // foo (a, b)

But giving the user freedom over the filled slot(s) could be useful too.

@chronium
Copy link
Owner Author

Fill from left on |> and fill from right on <|
Other than that, all perfect examples of use cases. Cheers!

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

No branches or pull requests

2 participants