#partial #function #curve

partial_function

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

7 releases (4 breaking)

0.5.0 May 24, 2020
0.4.0 Aug 9, 2018
0.3.0 Aug 8, 2018
0.2.0 Sep 27, 2017
0.1.2 Sep 27, 2017

#525 in Rust patterns

Download history 20/week @ 2022-06-07 9/week @ 2022-06-14 13/week @ 2022-06-21 10/week @ 2022-06-28 12/week @ 2022-07-05 14/week @ 2022-07-12 23/week @ 2022-07-19 15/week @ 2022-07-26 23/week @ 2022-08-02 25/week @ 2022-08-09 13/week @ 2022-08-16 16/week @ 2022-08-23 12/week @ 2022-08-30 19/week @ 2022-09-06 22/week @ 2022-09-13 10/week @ 2022-09-20

63 downloads per month
Used in 2 crates

Apache-2.0

10KB
115 lines

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

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

Dependencies

~220–630KB
~15K SLoC