Created
September 16, 2021 18:35
-
-
Save darddan/9c1fb775b3271b9bbe13ba875e12d156 to your computer and use it in GitHub Desktop.
|> in rust
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
pub trait Pipe<Output> { | |
fn pipe(self, pipe_fn: fn(Self) -> Output) -> Output; | |
} | |
impl <T, Output> Pipe<Output> for T { | |
fn pipe(self, pipe_fn: fn(Self) -> Output) -> Output { | |
pipe_fn(self) | |
} | |
} | |
fn main() { | |
let value = 2 | |
.pipe(|val| val+2) | |
.pipe(|val| val * 3) | |
.pipe(|val| format!("value = {}", val)); | |
println!("{}", value); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Or something like: