Hi all
I think Chain.jl is a phenomenal package.
I’ve submitted a package called Chainables.jl to the General registry, and a registry maintainer suggested I bring up the idea here to get feedback and thoughts.
The goal of the package is to make it easier to keep @chain pipelines going and improve readability in cases where functions expect function/lambda arguments first.
Chainables provides macro versions of common functions with reversed argument order, so the data can appear first in the pipeline. For example:
map(f, x) → @map(x, f)
This allows functions to be used more naturally inside @chain blocks, and there are utilities to make other functions more @chain-able as well.
Repo:
Example
Current way
@chain 1:10 begin
zip(21:30)
collect
filter(t -> t[2] <= 25, _)
map(t -> t[1], _)
end
Chainables way
@chain 1:10 begin
zip(21:30)
collect
@filter @unpack (a, b) -> b <= 25
@map @unpack (a, b) -> a
end
# can use Iterators.filter instead
@chain 1:10 begin
zip(21:30)
@filteriter @unpack (a, b) -> b <= 25
@map @unpack (a, b) -> a
end
I’m mainly interested in hearing:
- whether people are interested in this kind of utility
- whether similar functionality already exists elsewhere in the ecosystem
One design choice worth mentioning is that the macros intentionally use the same function names, e.g. map becomes @map.
Keen to hear your thoughts!