-
Notifications
You must be signed in to change notification settings - Fork 107
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
Emulating Maybe style branching #122
Comments
Couple things:
|
Hey! Of course this is just to save keystrokes and without using the full Monad, just a way to branch the data flow. The pipeline operator itself can be emulated with a one-liner. const pipeline = (input,...funcs) => funcs.reduce( (acc,fn) => fn(acc) , input )
pipeline(
10,
/* |> */ double,
/* |> */ triple,
) Thanks for the link, you're right in that I just saw
const inc = # + 1 |
@babakness The url
|> await api.get(#)
|> processResponse Writing it without the pipeline doesn't make sense: const awaitThing = await # We can't assign this to a function, because |
I agree, the Yet the same feeling about that apply here. I feel this should really be its own operator url
|: await api.get(#)
|> processResponse This is better. Because people will do this const foo = url |> await api.get(#) Or much worse const T = x => f => f(x)
const foo = bar |> T(`... really long template. Call #800-333-5555 press # followed by 0 to get an operator. ${ # }`)
const foo = bar |> T(`... really long template. Call #800-333-5555 press # followed by 0 to get an operator.`) In one situation we have Its confusing. With a |
I personally think Smart Pipelines are complex enough as-is without needing to then remember separate rules for when you can and can't use the Lexical Topic. The second |
You may be intrigued to hear that I've been looking into this thing myself, with a built-in nullable wrapper. I'm just attacking the issue from a more functional mindset than a syntax mindset. |
Closing this issue, as the proposal has advanced to stage 2 with Hack-style syntax. (However, extending piping to cover functor/monadic cases is very interesting, and would be great to pursue in the future.) |
It would be very useful to branch logic within a pipeline. Consider the Maybe Monad
https://mostly-adequate.gitbooks.io/mostly-adequate-guide/ch08.html#schr%C3%B6dingers-maybe
Maybe (no pun) we can have something like this, suppose
<!>
was a pipeline catch expressionOr something like that. Some way to differ evaluation to the end of a pipeline to handle a special case.
I realize the
Maybish
proposed here is not a Monad, just wanting to illustrate a way to branch.The text was updated successfully, but these errors were encountered: