Functionality
Adds support for chaining functions in a functional way.
Pipe
The following 9 methods are added to all types:
| pipe syntax | traditional syntax equivalent |
|---|---|
x.pipe(f) |
f(x) |
x.pipe_ref(f) |
f(&x) |
x.pipe_mut(f) |
f(&mut x) |
x.pipe_as_ref(f) |
f(x.as_ref()) |
x.pipe_as_mut(f) |
f(x.as_mut()) |
x.pipe_deref(f) |
f(&x) |
x.pipe_deref_mut(f) |
f(&mut x) |
x.pipe_borrow(f) |
f(x.borrow()) |
x.pipe_borrow_mut(f) |
f(x.borrow_mut()) |
These are imported directly from the pipe-trait crate.
Example
use *;
let inc = ;
let double = ;
let square = ;
let a = .pipe.pipe.pipe;
let b = square;
assert_eq!;
Mutate
The method .mutate(..) is also added to all types.
Example
use *;
let sorted = vec!.mutate;
assert_eq!;
Future Plans
I plan on coming back to this crate and adding more useful things to it. If you have any ideas, please send them to me! Contact me at yony252525@gmail.com.
I do want to only put important, useful things in this crate. For example, I thought about adding a macro to make piping
easier (something like pipe! { input |> f1 |> f2 |> ... }) but it sounded not nearly as essential as .pipe and .mutate
for my kind of programing.