#Is there a converse of `|>`

1 messages · Page 1 of 1 (latest)

olive coral
#

Sometimes I have a pipeline that creates a function and I'd like to eventually apply the resulting function at a given argument, is there an idiomatic way to achieve this behaviour?

For instance, this works:

  let neato = 1 |> int.is_even

However, sometimes I have the other way around (namely with higher-order functions in the pipeline):

  let negate = fn(p) { fn(x) { !p(x) } }
  let oh_no = int.is_even |> negate |> fn(f) { f(1) }

I dislike having to use the fn here, and I'd like to have something like:

  let _i_wish = int.is_even |> negate |> _(1) // 💢 Invalid Gleam

Thanks!

polar shell
#

Nope! Gleam generally prefers to be explicit, and generally doesn't include much in the way of syntax sugar. It's by design - one way to do things

hardy flint
#

Not using pipe would make these all much easier to read imo

#

It's common for people new to languages with |> to try to always use them, resulting in harder to understand code. Like all thing, it should not be used all the time, and if there's friction when trying to use it that could be a sign that it's not a good time to use that tool

vestal seal
#

New gleamlin pipe addiction support group lucysparkles