Skip to content

empty do chain syntax#46

Open
jkrumbiegel wants to merge 3 commits into
masterfrom
function-chain
Open

empty do chain syntax#46
jkrumbiegel wants to merge 3 commits into
masterfrom
function-chain

Conversation

@jkrumbiegel

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown

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
Copy Markdown

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
Copy Markdown
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