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
72
73
74
75
76
77
78
79
80
81
//! Contexts that can be initialized with a value via the [`pure`] operation.
//!
//! ### Examples
//!
//! ```
//! use fp_library::{
//! brands::*,
//! functions::*,
//! };
//!
//! let x = pure::<OptionBrand, _>(5);
//! assert_eq!(x, Some(5));
//! ```
#[fp_macros::document_module]
mod inner {
use {
crate::kinds::*,
fp_macros::*,
};
/// A type class for contexts that can be initialized with a value.
#[kind(type Of<'a, A: 'a>: 'a;)]
pub trait Pointed {
/// The value wrapped in the context.
///
/// This method wraps a value in a context.
#[document_signature]
///
#[document_type_parameters("The lifetime of the value.", "The type of the value to wrap.")]
///
#[document_parameters("The value to wrap.")]
///
#[document_returns("A new context containing the value.")]
#[document_examples]
///
/// ```
/// use fp_library::{
/// brands::*,
/// functions::*,
/// };
///
/// let x = pure::<OptionBrand, _>(5);
/// assert_eq!(x, Some(5));
/// ```
fn pure<'a, A: 'a>(a: A) -> Apply!(<Self as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, A>);
}
/// The value wrapped in the context.
///
/// Free function version that dispatches to [the type class' associated function][`Pointed::pure`].
#[document_signature]
///
#[document_type_parameters(
"The lifetime of the value.",
"The brand of the context.",
"The type of the value to wrap."
)]
///
#[document_parameters("The value to wrap.")]
///
#[document_returns("A new context containing the value.")]
#[document_examples]
///
/// ```
/// use fp_library::{
/// brands::*,
/// functions::*,
/// };
///
/// let x = pure::<OptionBrand, _>(5);
/// assert_eq!(x, Some(5));
/// ```
pub fn pure<'a, Brand: Pointed, A: 'a>(
a: A
) -> Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, A>) {
Brand::pure(a)
}
}
pub use inner::*;