Skip to content

loop and branch control flow abstraction for (by-value) pipes#16

Open
nerditation wants to merge 3 commits intomyrrlyn:mainfrom
nerditation:control-flow-pipe
Open

loop and branch control flow abstraction for (by-value) pipes#16
nerditation wants to merge 3 commits intomyrrlyn:mainfrom
nerditation:control-flow-pipe

Conversation

@nerditation
Copy link

I've added three pipe methods (names to be bikeshedded):

these are mostly to deal with builder patterns where the builder type is implemented with a self receiver. I add a motivating example to the documentation of each method.

my questions:

  • I don't have a use case for Result personally, so I didn't include a pipe_for_ok(). is this use case common? should I add it "just for completeness"?

  • I find builder patterns with a &mut self receiver is generally less annoying with control flows, since you don't need mut bindings and re-assignment, nor the else clause, so I'm satisfied with tap_mut() for similar use cases, and decided to not add similar constructs for Tap. I'd like to hear other's opinion.

`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.
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.

1 participant