Chain.jl
Chain.jl copied to clipboard
empty do chain syntax
Allows this
@chain begin
["hello", "world"]
@chain map() do
collect
@chain filter() do
uppercase
_ ∉ ('E', 'L')
end
String
end
end
instead of this
@chain begin
["hello", "world"]
map(_) do x
@chain x begin
collect
filter(_) do y
@chain y begin
uppercase
_ ∉ ('E', 'L')
end
end
String
end
end
end
I don't hate this. It's kind of cool. But it is unnecessary in the sense that DataFramesMeta.jl doesn't really have a use-case for this kind of thing.
Could you give more examples for where this kind of feature would be useful?
Dataframesmeta has no need for nesting, that's true. I've mostly needed better nesting when dealing with other collections, for example when doing string parsing or web scraping or things like that. There's really no good idiom to continue a chain at a lower nesting level, unless you skip out of the logic with a normal map, or put the chain in manually, but that loses the succinctness of the macro.
FWIW I've been using this branch for Advent of Code these past few days, where there's a decent amount of parsing and general transformations. I like it a lot, as discussed in https://github.com/jkrumbiegel/Chain.jl/issues/45. Here's an example:
links = @chain input begin
strip
split("\n")
@chain map() do
split("-")
Pair(_...)
[_, _ |> reverse]
end
flatten
collect
end
FWIW this just appeared on my notifications; it looks like the same design! https://discourse.julialang.org/t/ann-datapipes-jl/60734/61
I posted the PR with the design on slack, possibly got it from there