Crates.io | composing |
lib.rs | composing |
version | 0.2.0 |
source | src |
created_at | 2023-04-26 08:23:59.439241 |
updated_at | 2023-04-26 09:47:57.840395 |
description | Tools to compose functions |
homepage | |
repository | https://github.com/FedericoStra/composing |
max_upload_size | |
id | 849171 |
size | 13,679 |
Tools to compose functions
This library exports two macros, compose_expr
and compose_fn
,
which allow to easily compose expressions and functions respectively.
They both support right-to-left and left-to-right composition.
use composing::*;
fn plus_one(x: i32) -> i32 { x + 1 }
fn times_two(x: i32) -> i32 { x * 2 }
fn to_string(x: i32) -> String { x.to_string() }
let composition = compose_fn!(to_string, plus_one, times_two);
assert_eq!(composition(17), "35");
let composition = compose_fn!(times_two => plus_one => to_string);
assert_eq!(composition(17), "35");