-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Expose ComposedFunction as a public API #37517
Merged
Merged
Changes from 1 commit
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
47802b1
document ComposedFunction
jw3126 40f3179
Update base/operators.jl
jw3126 5a76b52
Update base/operators.jl
jw3126 a2a73a7
Update base/operators.jl
tkf 11b7f35
Update base/operators.jl
jw3126 feaf87f
add ComposedFunction to News.md
jw3126 d7195b8
Give more descriptive names to the fields of ComposedFunction
jw3126 400de93
Update base/operators.jl
tkf 90e0015
export ComposedFunction
jw3126 b79acfe
Merge branch 'doc_composition' of github.com:jw3126/julia into doc_co…
jw3126 d722191
improve ComposedFunction docstring
jw3126 d96d24d
improve ComposedFunction docstring
jw3126 5cb6291
Merge branch 'master' into doc_composition
jw3126 3420ac6
fix ComposedFunction doctest
jw3126 37908d6
Merge branch 'doc_composition' of github.com:jw3126/julia into doc_co…
jw3126 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Update base/operators.jl
Co-authored-by: Jonas Schulze <jonas.schulze7@t-online.de>
- Loading branch information
commit 5a76b529d53d8fcf8c24285e0f36322ebceaf99a
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would actually prefer to name the fields to e.g.
outer, inner
instead off,g
. It is hard to remember if this modelsf∘g
org∘f
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm somewhat neutral about the choice of the field names. I see
f
andg
as something likex
andy
. It's technically arbitrary but I've seen it many times so I don't think it's super hard to guess the ordering.Just as a note, one (rather weak) upside of keep using
f
andg
is that we can defineComposedFunction
for olderjulia
versions as done in DataFrames.jl (JuliaData/DataFrames.jl#2274 (comment)). However, it doesn't matter much since 1.6 soon will be the LTS (and we can even definegetproperty
for the closure in Compat.jl).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the order is not easy to guess at all. Just have a look at the wikipedia article. There the order
g∘f
is more dominant, which is opposed to the current order we use.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My personal first guess was btw
g∘f
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, I sometimes get inner/outer opposite somehow (though this is probably just me). Since you can always flip the arrows (and which direction feels natural depends on the context), I'm not sure if there are truly unambiguous names for them. But I'm likely nitpicking. I agree inner/outer is more descriptive for function composition.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With
outer, inner
it is at least clear thatc::ComposedFunction
talks aboutc.outer(c.inner(x))
. Withf,g
it is unclear whether we are talking aboutc.f(c.g(x))
orc.g(c.f(x))
. Remembering the direction of arrows is an independent problem that comes up in both scenarios.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Btw, I also get inner outer wrong sometimes, but I can usually recover by pure reasoning without having to dig up the source.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree it's easier to remember and be confident which function is applied first with inner/outer. I think I'm in the team inner/outer now. How about renaming them in this PR and see the reactions of other reviewers?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the little it is worth, I think
f
andg
are fine and their exact interpretation can be clarified in the docstring. That way there doesn't need to be any work on Compat.jl or in other packages.If you stick with inner and outer, then I think line 881 needs to change:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No,
f
andg
are confusing, we should not force people to look up the docstring all the time. Also @tkf has a PR to compatJuliaLang/Compat.jl#720 and supporting
f
andg
is the easy part of that code.