1#[fp_macros::document_module]
30pub(crate) mod inner {
31 use {
32 crate::{
33 classes::{
34 Applicative,
35 LiftFn,
36 RefTraversable,
37 Traversable,
38 },
39 dispatch::{
40 Ref,
41 Val,
42 },
43 kinds::*,
44 },
45 fp_macros::*,
46 };
47
48 #[document_type_parameters(
55 "The lifetime of the values.",
56 "The brand of the cloneable function to use.",
57 "The brand of the traversable structure.",
58 "The type of the elements in the input structure.",
59 "The type of the elements in the output structure.",
60 "The applicative functor brand for the computation.",
61 "The container type (owned or borrowed), inferred from the argument.",
62 "Dispatch marker type, inferred automatically. Either [`Val`](crate::dispatch::Val) or [`Ref`](crate::dispatch::Ref)."
63 )]
64 #[document_parameters("The closure implementing this dispatch.")]
65 pub trait TraverseDispatch<
66 'a,
67 FnBrand,
68 Brand: Kind_cdc7cd43dac7585f,
69 A: 'a,
70 B: 'a,
71 F: Kind_cdc7cd43dac7585f,
72 FTA,
73 Marker,
74 > {
75 #[document_signature]
77 #[document_parameters("The structure to traverse.")]
79 #[document_returns("The combined result in the applicative context.")]
81 #[document_examples]
82 fn dispatch(
94 self,
95 ta: FTA,
96 ) -> 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>)>);
97 }
98
99 #[document_type_parameters(
106 "The lifetime of the values.",
107 "The cloneable function brand (unused by Val path).",
108 "The brand of the traversable structure.",
109 "The type of the elements in the input structure.",
110 "The type of the elements in the output structure.",
111 "The applicative functor brand.",
112 "The closure type."
113 )]
114 #[document_parameters("The closure that takes owned values.")]
115 impl<'a, FnBrand, Brand, A, B, F, Func>
116 TraverseDispatch<
117 'a,
118 FnBrand,
119 Brand,
120 A,
121 B,
122 F,
123 Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, A>),
124 Val,
125 > for Func
126 where
127 Brand: Traversable,
128 A: 'a + Clone,
129 B: 'a + Clone,
130 F: Applicative,
131 Func: Fn(A) -> Apply!(<F as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, B>) + 'a,
132 Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, B>): Clone,
133 Apply!(<F as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, B>): Clone,
134 {
135 #[document_signature]
136 #[document_parameters("The structure to traverse.")]
138 #[document_returns("The combined result in the applicative context.")]
140 #[document_examples]
141 fn dispatch(
153 self,
154 ta: Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, A>),
155 ) -> 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>)>)
156 {
157 Brand::traverse::<A, B, F>(self, ta)
158 }
159 }
160
161 #[document_type_parameters(
172 "The lifetime of the values.",
173 "The borrow lifetime.",
174 "The cloneable function brand.",
175 "The brand of the traversable structure.",
176 "The type of the elements in the input structure.",
177 "The type of the elements in the output structure.",
178 "The applicative functor brand.",
179 "The closure type."
180 )]
181 #[document_parameters("The closure that takes references.")]
182 impl<'a, 'b, FnBrand, Brand, A, B, F, Func>
183 TraverseDispatch<
184 'a,
185 FnBrand,
186 Brand,
187 A,
188 B,
189 F,
190 &'b Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, A>),
191 Ref,
192 > for Func
193 where
194 Brand: RefTraversable,
195 FnBrand: LiftFn + 'a,
196 A: 'a + Clone,
197 B: 'a + Clone,
198 F: Applicative,
199 Func: Fn(&A) -> Apply!(<F as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, B>) + 'a,
200 Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, B>): Clone,
201 Apply!(<F as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, B>): Clone,
202 {
203 #[document_signature]
204 #[document_parameters("A reference to the structure to traverse.")]
206 #[document_returns("The combined result in the applicative context.")]
208 #[document_examples]
209 fn dispatch(
223 self,
224 ta: &'b Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, A>),
225 ) -> 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>)>)
226 {
227 Brand::ref_traverse::<FnBrand, A, B, F>(self, ta)
228 }
229 }
230
231 #[document_signature]
243 #[document_type_parameters(
245 "The lifetime of the values.",
246 "The brand of the cloneable function to use (must be specified explicitly).",
247 "The container type (owned or borrowed). Brand is inferred from this.",
248 "The type of the elements in the input structure.",
249 "The type of the elements in the output structure.",
250 "The applicative functor brand (must be specified explicitly).",
251 "Dispatch marker type, inferred automatically."
252 )]
253 #[document_parameters(
255 "The function to apply to each element, returning a value in an applicative context.",
256 "The traversable structure (owned for Val, borrowed for Ref)."
257 )]
258 #[document_returns("The structure wrapped in the applicative context.")]
260 #[document_examples]
261 pub fn traverse<'a, FnBrand, FA, A: 'a, B: 'a, F: Kind_cdc7cd43dac7585f, Marker>(
272 func: impl TraverseDispatch<
273 'a,
274 FnBrand,
275 <FA as InferableBrand_cdc7cd43dac7585f>::Brand,
276 A,
277 B,
278 F,
279 FA,
280 Marker,
281 >,
282 ta: FA,
283 ) -> Apply!(<F as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, Apply!(<<FA as InferableBrand!(type Of<'a, A: 'a>: 'a;)>::Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, B>)>)
284 where
285 FA: InferableBrand_cdc7cd43dac7585f, {
286 func.dispatch(ta)
287 }
288
289 pub mod explicit {
296 use super::*;
297
298 #[document_signature]
319 #[document_type_parameters(
321 "The lifetime of the values.",
322 "The brand of the cloneable function to use.",
323 "The brand of the traversable structure.",
324 "The type of the elements in the input structure.",
325 "The type of the elements in the output structure.",
326 "The applicative functor brand.",
327 "The container type (owned or borrowed), inferred from the argument.",
328 "Dispatch marker type, inferred automatically."
329 )]
330 #[document_parameters(
332 "The function to apply to each element, returning a value in an applicative context.",
333 "The traversable structure (owned for Val, borrowed for Ref)."
334 )]
335 #[document_returns("The structure wrapped in the applicative context.")]
337 #[document_examples]
339 pub fn traverse<
359 'a,
360 FnBrand,
361 Brand: Kind_cdc7cd43dac7585f,
362 A: 'a,
363 B: 'a,
364 F: Kind_cdc7cd43dac7585f,
365 FTA,
366 Marker,
367 >(
368 func: impl TraverseDispatch<'a, FnBrand, Brand, A, B, F, FTA, Marker>,
369 ta: FTA,
370 ) -> 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>)>)
371 {
372 func.dispatch(ta)
373 }
374 }
375}
376
377pub use inner::*;