Skip to content
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

empty do chain syntax #46

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

empty do chain syntax #46

wants to merge 3 commits into from

Conversation

jkrumbiegel
Copy link
Owner

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

@jkrumbiegel jkrumbiegel linked an issue Dec 9, 2021 that may be closed by this pull request
@pdeffebach
Copy link
Contributor

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?

@jkrumbiegel
Copy link
Owner Author

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.

@max-sixty
Copy link

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 #45. Here's an example:

links = @chain input begin
    strip
    split("\n")
    @chain map() do
        split("-")
        Pair(_...) 
        [_, _ |> reverse]
    end
    flatten
    collect
end

@max-sixty
Copy link

FWIW this just appeared on my notifications; it looks like the same design! https://discourse.julialang.org/t/ann-datapipes-jl/60734/61

@jkrumbiegel
Copy link
Owner Author

I posted the PR with the design on slack, possibly got it from there

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Approach for nesting a map
3 participants