functionality 1.0.2

Rust |> Functional programming = 💖. Useful traits, functions and macros for prettier code.
Documentation
  • Coverage
  • 37.5%
    6 out of 16 items documented3 out of 13 items with examples
  • Size
  • Source code size: 10.72 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 2.79 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 38s Average build duration of successful builds.
  • all releases: 21s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • yonatan-reicher

Functionality

Test Crates.io Version

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 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

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.