1#[fp_macros::document_module]
17mod inner {
18 use {
19 crate::{
20 classes::*,
21 functions::*,
22 kinds::*,
23 },
24 fp_macros::*,
25 };
26
27 pub trait Traversable: Functor + Foldable {
31 #[document_signature]
40 #[document_type_parameters(
42 "The lifetime of the elements.",
43 "The type of the elements in the traversable structure.",
44 "The type of the elements in the resulting traversable structure.",
45 "The applicative context."
46 )]
47 #[document_parameters(
49 "The function to apply to each element, returning a value in an applicative context.",
50 "The traversable structure."
51 )]
52 #[document_returns("The traversable structure wrapped in the applicative context.")]
54 #[document_examples]
55 fn traverse<'a, A: 'a + Clone, B: 'a + Clone, F: Applicative>(
67 func: impl Fn(A) -> Apply!(<F as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, B>) + 'a,
68 ta: Apply!(<Self as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, A>),
69 ) -> Apply!(<F as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, Apply!(<Self as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, B>)>)
70 where
71 Apply!(<Self as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, B>): Clone,
72 Apply!(<F as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, B>): Clone, {
73 Self::sequence::<B, F>(Self::map::<
74 A,
75 Apply!(<F as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, B>),
76 >(func, ta))
77 }
78
79 #[document_signature]
83 #[document_type_parameters(
85 "The lifetime of the elements.",
86 "The type of the elements in the traversable structure.",
87 "The applicative context."
88 )]
89 #[document_parameters(
91 "The traversable structure containing values in an applicative context."
92 )]
93 #[document_returns("The traversable structure wrapped in the applicative context.")]
95 #[document_examples]
96 fn sequence<'a, A: 'a + Clone, F: Applicative>(
108 ta: Apply!(<Self as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, Apply!(<F as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, A>)>)
109 ) -> Apply!(<F as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, Apply!(<Self as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, A>)>)
110 where
111 Apply!(<F as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, A>): Clone,
112 Apply!(<Self as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, A>): Clone, {
113 Self::traverse::<Apply!(<F as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, A>), A, F>(
114 identity, ta,
115 )
116 }
117 }
118
119 #[document_signature]
123 #[document_type_parameters(
125 "The lifetime of the elements.",
126 "The brand of the traversable structure.",
127 "The type of the elements in the traversable structure.",
128 "The type of the elements in the resulting traversable structure.",
129 "The applicative context."
130 )]
131 #[document_parameters(
133 "The function to apply to each element, returning a value in an applicative context.",
134 "The traversable structure."
135 )]
136 #[document_returns("The traversable structure wrapped in the applicative context.")]
138 #[document_examples]
139 pub fn traverse<'a, Brand: Traversable, A: 'a + Clone, B: 'a + Clone, F: Applicative>(
151 func: impl Fn(A) -> Apply!(<F as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, B>) + 'a,
152 ta: Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, A>),
153 ) -> Apply!(<F as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, B>)>)
154 where
155 Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, B>): Clone,
156 Apply!(<F as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, B>): Clone, {
157 Brand::traverse::<A, B, F>(func, ta)
158 }
159
160 #[document_signature]
164 #[document_type_parameters(
166 "The lifetime of the elements.",
167 "The brand of the traversable structure.",
168 "The type of the elements in the traversable structure.",
169 "The applicative context."
170 )]
171 #[document_parameters("The traversable structure containing values in an applicative context.")]
173 #[document_returns("The traversable structure wrapped in the applicative context.")]
175 #[document_examples]
176 pub fn sequence<'a, Brand: Traversable, A: 'a + Clone, F: Applicative>(
188 ta: Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, Apply!(<F as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, A>)>)
189 ) -> Apply!(<F as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, A>)>)
190 where
191 Apply!(<F as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, A>): Clone,
192 Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, A>): Clone, {
193 Brand::sequence::<A, F>(ta)
194 }
195}
196
197pub use inner::*;