https://github.com/yonatan-reicher/functionality
Rust |> functional programing = 💖
https://github.com/yonatan-reicher/functionality
functional-programming pipes rust trait
Last synced: 9 days ago
JSON representation
Rust |> functional programing = 💖
- Host: GitHub
- URL: https://github.com/yonatan-reicher/functionality
- Owner: yonatan-reicher
- Created: 2025-02-22T23:51:01.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2026-04-26T05:44:21.000Z (about 2 months ago)
- Last Synced: 2026-04-26T07:24:05.999Z (about 2 months ago)
- Topics: functional-programming, pipes, rust, trait
- Language: Rust
- Homepage: https://crates.io/crates/functionality
- Size: 11.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 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:
| 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](https://github.com/KSXGitHub/pipe-trait).
### Example
```rust
use functionality::prelude::*;
let inc = |x| x + 1;
let double = |x| x + x;
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::*;
let sorted = vec![3, 2, 1].mutate(|v| v.sort());
assert_eq!(sorted, vec![1, 2, 3]);
```
## 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.