loop and branch control flow abstraction for (by-value) pipes#16
Open
nerditation wants to merge 3 commits intomyrrlyn:mainfrom
Open
loop and branch control flow abstraction for (by-value) pipes#16nerditation wants to merge 3 commits intomyrrlyn:mainfrom
nerditation wants to merge 3 commits intomyrrlyn:mainfrom
Conversation
`pipe_when()` is just a `pipe` with an `if-else` control flow: pipe_when self condition f = pipe self (if condition f else id)
similar to `pipe_when()`, but with a `if-let-else` instead of `if-else`
this is a generalization of `pipe_for_some()`, it is an abstraction of a `for`-loop.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
I've added three pipe methods (names to be bikeshedded):
Pipe::pipe_when(): abstraction ofif-elsethis is the same as
pipe_if()in add pipe_if method(s) #7Pipe::pipe_for_some(): abstraction ofif-let-elseforOptionthis is basically the
pipe_map()proposed in this comment of add pipe_if method(s) #7Pipe::pipe_for_each(): abstraction offor-loopthese are mostly to deal with builder patterns where the builder type is implemented with a
selfreceiver. I add a motivating example to the documentation of each method.my questions:
I don't have a use case for
Resultpersonally, so I didn't include apipe_for_ok(). is this use case common? should I add it "just for completeness"?I find builder patterns with a
&mut selfreceiver is generally less annoying with control flows, since you don't needmutbindings and re-assignment, nor theelseclause, so I'm satisfied withtap_mut()for similar use cases, and decided to not add similar constructs forTap. I'd like to hear other's opinion.