1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//! # Partial Functional types for Rust
//!
//! I have tried taking some functional programming types into Rust types.
//! You will find types that are in the group of [Semigroup] and [Monoid]s as well as [Functor](functor::Functor).
//!
//! It is meant to bring some more functional programming tricks in to rust.
//!
//! ## Examples
//! ```
//! use partial_functional::prelude::*;
//!
//! #[derive(Debug, PartialEq)]
//! struct OrderLine {
//! product_code: String,
//! quantity: Sum<u32>,
//! price: Sum<f32>,
//! }
//!
//! impl Semigroup for OrderLine {
//! fn combine(self, other: Self) -> Self {
//! Self {
//! product_code: String::from("TOTAL"),
//! quantity: self.quantity.combine(other.quantity),
//! price: self.price.combine(other.price),
//! }
//! }
//! }
//!
//! impl Monoid for OrderLine {
//! fn empty() -> Self {
//! Self { product_code: String::from(""), quantity: Sum::empty(), price: Sum::empty() }
//! }
//! }
//!
//! let order_lines = vec![
//! OrderLine { product_code: String::from("AAA"), quantity: Sum(2), price: Sum(19.98) },
//! OrderLine { product_code: String::from("BBB"), quantity: Sum(1), price: Sum(1.99) },
//! OrderLine { product_code: String::from("CCC"), quantity: Sum(3), price: Sum(3.99) },
//! ];
//!
//! let mut total = order_lines
//! .into_iter()
//! .fold(OrderLine::empty(), |acc, item| acc.combine(item));
//!
//! let expected = OrderLine { product_code: "TOTAL".into(), quantity: 6.into(), price: 25.96.into() };
//! assert_eq!(expected, total);
//!
//! let new_line = OrderLine { product_code: "DDD".into(), quantity: 1.into(), price: 29.98.into() };
//! total = total.combine(new_line);
//!
//! let expected = OrderLine { product_code: "TOTAL".into(), quantity: 7.into(), price: 55.94.into() };
//! assert_eq!(expected, total);
//! ```
//!
//! A more elaborate example of the above can be run with `cargo run --example orderline`
pub use *;
pub use ;
pub use Semigroup;