Closed weswigham closed 10 years ago
Idea: Let there be a default functionality for pipelines (either apply
or a foldl
kinda deal), but let it be defined on a per-function basis using a :pipe
metafunction (along the same lines as :before
or :after
) that is passed a list of the piped things. This means I could have something like
List<T> -> List<T> -> List<T>
def append(a, b)
a.append(b)
List<List<T>> -> List<T>
def append:pipe(lst)
ret = []
lst.each -> |v|
append(ret, v)
ret
I like this idea.
A single declaration, multiple application operator will be considered for v1.0.
This is nice. Why restrict it to
let
/cond
/match
? Why not let the|
syntax, hereby referred to as the 'pipeline syntax' to any unary or binary function/operator?Example use cases:
Binary operations:
Unary operation:
On unary operation, the pipline applies the unary operation to every pipeline'd object.
On a binary operation, the pipeline acts as a kind of upwards collapse (or a fold left, if you'd prefer). The first two are fed as inputs to the binary operation, and then the result is fed into it again along with the third input, then that result is fed in along with the 4th, and so on.
So yeah, don't restrict this syntax to
let
/cond
/match
, it looks pretty useful and pretty elsewhere.