# pipei
`pipei` provides `pipe{i}` methods that let you write function calls in a chaining style:
they bind the first argument to the receiver and return a closure for the remaining arguments.
Borrowed variants let you “view” a value as something else (e.g. `String` as `str`, `Vec<T>` as `[T]`),
and mutable borrowed variants let you update in place.
## Enabling arities
Enable the arities you need via features:
```toml
[dependencies]
pipei = "0.1" # default: features = ["up_to_5"]
# pipei = { version = "0.1", features = ["up_to_10"] }
# pipei = { version = "0.1", features = ["pipe0", "pipe1", "pipe3"] }
```
## Basic chaining with `pipe{i}` (by value)
```rust
use pipei::{Pipe1, Pipe2};
fn add(x: i32, y: i32) -> i32 { x + y }
fn mul(x: i32, y: i32) -> i32 { x * y }
fn lin(x: i32, a: i32, b: i32) -> i32 { a * x + b }
let out = 2
.pipe1(add)(3)
.pipe1(mul)(10)
.pipe2(lin)(7, 1);
assert_eq!(out, 351);
```
## Pipe0
```rust
use pipei::Pipe0;
fn consume_len(s: String) -> usize { s.len() }
let n = "hello".to_string().pipe0(consume_len)();
assert_eq!(n, 5);
```
## Borrowed piping
```rust
use pipei::Pipe2Ref;
use core::borrow::Borrow;
fn slice_len(s: &str, start: usize, end: usize) -> usize {
s[start..end].len()
}
let n = "hello world".to_string()
.pipe2_with(|x| x.borrow(), slice_len)(0, 5);
assert_eq!(n, 5);
```
## Mutable piping
```rust
use pipei::Pipe1Ref;
fn push_ret(v: &mut Vec<i32>, x: i32) -> &mut Vec<i32>{ v.push(x); v}
let mut v = vec![];
v
.pipe1_with_mut(|x| x, push_ret)(1)
.pipe1_with_mut(|x| x, push_ret)(2)
.pipe1_with_mut(|x| x, push_ret)(3);
assert_eq!(v, vec![1,2,3]);
```