1#[fp_macros::document_module]
17mod inner {
18 use {
19 crate::{
20 classes::*,
21 functions::*,
22 kinds::*,
23 },
24 fp_macros::*,
25 };
26
27 #[document_examples]
37 pub trait Traversable: Functor + Foldable {
65 #[document_signature]
74 #[document_type_parameters(
76 "The lifetime of the elements.",
77 "The type of the elements in the traversable structure.",
78 "The type of the elements in the resulting traversable structure.",
79 "The applicative context."
80 )]
81 #[document_parameters(
83 "The function to apply to each element, returning a value in an applicative context.",
84 "The traversable structure."
85 )]
86 #[document_returns("The traversable structure wrapped in the applicative context.")]
88 #[document_examples]
89 fn traverse<'a, A: 'a + Clone, B: 'a + Clone, F: Applicative>(
101 func: impl Fn(A) -> Apply!(<F as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, B>) + 'a,
102 ta: Apply!(<Self as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, A>),
103 ) -> 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>)>)
104 where
105 Apply!(<Self as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, B>): Clone,
106 Apply!(<F as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, B>): Clone, {
107 Self::sequence::<B, F>(Self::map::<
108 A,
109 Apply!(<F as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, B>),
110 >(func, ta))
111 }
112
113 #[document_signature]
117 #[document_type_parameters(
119 "The lifetime of the elements.",
120 "The type of the elements in the traversable structure.",
121 "The applicative context."
122 )]
123 #[document_parameters(
125 "The traversable structure containing values in an applicative context."
126 )]
127 #[document_returns("The traversable structure wrapped in the applicative context.")]
129 #[document_examples]
130 fn sequence<'a, A: 'a + Clone, F: Applicative>(
142 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>)>)
143 ) -> 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>)>)
144 where
145 Apply!(<F as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, A>): Clone,
146 Apply!(<Self as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, A>): Clone, {
147 Self::traverse::<Apply!(<F as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, A>), A, F>(
148 identity, ta,
149 )
150 }
151 }
152
153 #[document_signature]
157 #[document_type_parameters(
159 "The lifetime of the elements.",
160 "The brand of the traversable structure.",
161 "The type of the elements in the traversable structure.",
162 "The type of the elements in the resulting traversable structure.",
163 "The applicative context."
164 )]
165 #[document_parameters(
167 "The function to apply to each element, returning a value in an applicative context.",
168 "The traversable structure."
169 )]
170 #[document_returns("The traversable structure wrapped in the applicative context.")]
172 #[document_examples]
173 pub fn traverse<'a, Brand: Traversable, A: 'a + Clone, B: 'a + Clone, F: Applicative>(
185 func: impl Fn(A) -> Apply!(<F as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, B>) + 'a,
186 ta: Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, A>),
187 ) -> 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>)>)
188 where
189 Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, B>): Clone,
190 Apply!(<F as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, B>): Clone, {
191 Brand::traverse::<A, B, F>(func, ta)
192 }
193
194 #[document_signature]
198 #[document_type_parameters(
200 "The lifetime of the elements.",
201 "The brand of the traversable structure.",
202 "The type of the elements in the traversable structure.",
203 "The applicative context."
204 )]
205 #[document_parameters("The traversable structure containing values in an applicative context.")]
207 #[document_returns("The traversable structure wrapped in the applicative context.")]
209 #[document_examples]
210 pub fn sequence<'a, Brand: Traversable, A: 'a + Clone, F: Applicative>(
222 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>)>)
223 ) -> 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>)>)
224 where
225 Apply!(<F as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, A>): Clone,
226 Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, A>): Clone, {
227 Brand::sequence::<A, F>(ta)
228 }
229}
230
231pub use inner::*;