# Functionality
[](https://github.com/yonatan-reicher/functionality/actions?query=workflow%3ATest)
[](https://crates.io/crates/functionality)
Adds support for chaining functions in a functional way.
## Pipe
The following 9 methods are added to all types:
| `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](https://github.com/KSXGitHub/pipe-trait).
### Example
```rust
use functionality::prelude::*;
let square = |x| x * x;
let a = (123i32).pipe(inc).pipe(double).pipe(square);
let b = square(double(inc(123i32)));
assert_eq!(a, b);
```
## Mutate
The method `.mutate(..)` is also added to all types.
### Example
```rust
use functionality::prelude::*;
```
## 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.