No description
Find a file
2022-02-05 14:57:23 -05:00
.idea tried stuff, and failed 2018-08-08 22:44:30 -04:00
src Proposal to add macros These would: 1) Hide from the syntax a few design choices that the user need not be aware of (Box, .build()) 2) Make the representation a bit closer to how a mathematician would write it 2020-05-24 18:35:37 +02:00
tests Add wasm_bindgen_test. 2022-02-05 14:57:23 -05:00
.gitignore Added LowerPartialFunction 2018-08-08 19:23:54 -04:00
Cargo.toml Add wasm_bindgen_test. 2022-02-05 14:57:23 -05:00
LICENSE Initial commit 2017-09-27 12:04:21 -04:00
README.md macro example in readme 2020-05-25 08:27:22 -04:00

Support an Open Source Developer! ♥️

Become a patron

Partial Function

A clean way to define function as a set of smaller functions where each has defined start and end bounds.

Partial Function

Achieves the following:

f(x) = {
    x     if 0 <= x <   5
    x * 2 if 5 <= x <= 10
}

Expressed as:

let p = PartialFunction::new()
    .with(0.0, 5.0,  Box::new(|x| x    ))
    .with(5.0, 10.0, Box::new(|x| x * 2))
    .build();
assert_eq!(p.eval(5.0), Some(10.0));

or even as:

let p = partfn! {
    [0.0, 5.0]:  x -> x,
    [5.0, 10.0]: x -> x * 2,
};
assert_eq!(p.eval(5.0), Some(10.0));

Lower Partial Function

Achieves the following:

f(x) = {
    x     if 0 <= x <   5
    x * 2 if 5 <= x
}

Expressed as:

let f = LowerPartialFunction::new()
    .with(0.0, Box::new(|x| x    ))
    .with(5.0, Box::new(|x| x * 2))
    .build();
assert_eq!(f.eval(5.0), Some(10.0));

or even as:

let f = lowpartfn! {
    [0.0]: x -> x,
    [5.0]: x -> x * 2,
};
assert_eq!(f.eval(5.0), Some(10.0));

Adding To Your Project

Add the following to your Cargo.toml:

partial_function = "0.5.0"