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

Naming bikeshedding for opcompose (opposite composition function) #3

Closed
tkf opened this issue May 30, 2020 · 3 comments
Closed

Naming bikeshedding for opcompose (opposite composition function) #3

tkf opened this issue May 30, 2020 · 3 comments
Milestone

Comments

@tkf
Copy link
Member

tkf commented May 30, 2020

I can't really think about a better name but I'd like to rename it if we find a better one.

cc @jw3126

@tkf tkf added this to the 1.0 milestone May 30, 2020
@tkf
Copy link
Member Author

tkf commented May 30, 2020

Another possible ASCII-based API is to come up with something based on |>. The observation is that, if |> has a vararg form

|>(x, f, g, h) == x |> f |> g |> h == h(g(f(x)))

then opcompose is (args...) -> x -> |>(x, args...). So, if we have a "hole" or argument placeholder object, we can use |>(__placeholder_object__, functions...) instead of compose(functions...).

This can be done with <|(functions..., __placeholder_object__) too.

Implementation:

struct Hole end
const _ARG_ = Hole()
Base.:|>(::Hole, functions...) = (reverse(functions)...)
<|(args...) = |>(reverse(args)...)

Usage:

julia> |>(_ARG_, sin, cos, tan)
tan  cos  sin

julia> <|(sin, cos, tan, _ARG_)
sin  cos  tan

This might be a bit too "fancy" as I want CompositionsBase.jl to be super conservative. Maybe this can be put in CompositionsX.jl or something.

@jw3126
Copy link
Member

jw3126 commented May 30, 2020

I like compose and opcompose. I think Flux.jl uses Chain, which I also like as a name.

The Hole() trick is really clever and your tofu symbol is a good unicode name for it. I agree that this would be a better fit for a fancy CompositionsX.jl package.

Just to remind myself, ideally this package would be part of Base, it is currently not due to bad font support.

@tkf
Copy link
Member Author

tkf commented May 30, 2020

OK, good to have one more "vote" to opcompose :) I guess it is likely the current best approach. I'll experiment the hole thing in CompositionsX.jl.

BTW, just for the record, some more related links:

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

No branches or pull requests

2 participants