1#[fp_macros::document_module]
33pub(crate) mod inner {
34 use {
35 crate::{
36 classes::{
37 Applicative,
38 LiftFn,
39 RefTraversableWithIndex,
40 TraversableWithIndex,
41 WithIndex,
42 },
43 dispatch::{
44 Ref,
45 Val,
46 },
47 kinds::*,
48 },
49 fp_macros::*,
50 };
51
52 #[document_type_parameters(
59 "The lifetime of the values.",
60 "The brand of the cloneable function to use.",
61 "The brand of the traversable structure.",
62 "The type of the elements in the input structure.",
63 "The type of the elements in the output structure.",
64 "The applicative functor brand for the computation.",
65 "The container type (owned or borrowed), inferred from the argument.",
66 "Dispatch marker type, inferred automatically. Either [`Val`](crate::dispatch::Val) or [`Ref`](crate::dispatch::Ref)."
67 )]
68 #[document_parameters("The closure implementing this dispatch.")]
69 pub trait TraverseWithIndexDispatch<
70 'a,
71 FnBrand,
72 Brand: Kind_cdc7cd43dac7585f + WithIndex,
73 A: 'a,
74 B: 'a,
75 F: Kind_cdc7cd43dac7585f,
76 FTA,
77 Marker,
78 > {
79 #[document_signature]
81 #[document_parameters("The structure to traverse.")]
83 #[document_returns("The combined result in the applicative context.")]
85 #[document_examples]
86 fn dispatch(
100 self,
101 ta: FTA,
102 ) -> 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>)>);
103 }
104
105 #[document_type_parameters(
112 "The lifetime of the values.",
113 "The cloneable function brand (unused by Val path).",
114 "The brand of the traversable structure.",
115 "The type of the elements in the input structure.",
116 "The type of the elements in the output structure.",
117 "The applicative functor brand.",
118 "The closure type."
119 )]
120 #[document_parameters("The closure that takes an index and owned values.")]
121 impl<'a, FnBrand, Brand, A, B, F, Func>
122 TraverseWithIndexDispatch<
123 'a,
124 FnBrand,
125 Brand,
126 A,
127 B,
128 F,
129 Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, A>),
130 Val,
131 > for Func
132 where
133 Brand: TraversableWithIndex,
134 FnBrand: LiftFn + 'a,
135 A: 'a + Clone,
136 B: 'a + Clone,
137 F: Applicative,
138 Func:
139 Fn(Brand::Index, A) -> Apply!(<F as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, B>) + 'a,
140 Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, B>): Clone,
141 Apply!(<F as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, B>): Clone,
142 Brand::Index: 'a,
143 {
144 #[document_signature]
145 #[document_parameters("The structure to traverse.")]
147 #[document_returns("The combined result in the applicative context.")]
149 #[document_examples]
150 fn dispatch(
164 self,
165 ta: Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, A>),
166 ) -> 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>)>)
167 {
168 Brand::traverse_with_index::<A, B, F>(self, ta)
169 }
170 }
171
172 #[document_type_parameters(
182 "The lifetime of the values.",
183 "The borrow lifetime.",
184 "The cloneable function brand.",
185 "The brand of the traversable structure.",
186 "The type of the elements in the input structure.",
187 "The type of the elements in the output structure.",
188 "The applicative functor brand.",
189 "The closure type."
190 )]
191 #[document_parameters("The closure that takes an index and references.")]
192 impl<'a, 'b, FnBrand, Brand, A, B, F, Func>
193 TraverseWithIndexDispatch<
194 'a,
195 FnBrand,
196 Brand,
197 A,
198 B,
199 F,
200 &'b Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, A>),
201 Ref,
202 > for Func
203 where
204 Brand: RefTraversableWithIndex,
205 FnBrand: LiftFn + 'a,
206 A: 'a + Clone,
207 B: 'a + Clone,
208 F: Applicative,
209 Func:
210 Fn(Brand::Index, &A) -> Apply!(<F as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, B>) + 'a,
211 Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, B>): Clone,
212 Apply!(<F as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, B>): Clone,
213 Brand::Index: 'a,
214 {
215 #[document_signature]
216 #[document_parameters("A reference to the structure to traverse.")]
218 #[document_returns("The combined result in the applicative context.")]
220 #[document_examples]
221 fn dispatch(
236 self,
237 ta: &'b Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, A>),
238 ) -> 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>)>)
239 {
240 Brand::ref_traverse_with_index::<A, B, F>(self, ta)
241 }
242 }
243
244 #[document_signature]
257 #[document_type_parameters(
259 "The lifetime of the values.",
260 "The brand of the cloneable function to use (must be specified explicitly).",
261 "The container type (owned or borrowed). Brand is inferred from this.",
262 "The type of the elements in the input structure.",
263 "The type of the elements in the output structure.",
264 "The applicative functor brand (must be specified explicitly).",
265 "Dispatch marker type, inferred automatically."
266 )]
267 #[document_parameters(
269 "The indexed function to apply to each element, returning a value in an applicative context.",
270 "The traversable structure (owned for Val, borrowed for Ref)."
271 )]
272 #[document_returns("The structure wrapped in the applicative context.")]
274 #[document_examples]
275 pub fn traverse_with_index<'a, FnBrand, FA, A: 'a, B: 'a, F: Kind_cdc7cd43dac7585f, Marker>(
289 func: impl TraverseWithIndexDispatch<
290 'a,
291 FnBrand,
292 <FA as InferableBrand_cdc7cd43dac7585f>::Brand,
293 A,
294 B,
295 F,
296 FA,
297 Marker,
298 >,
299 ta: FA,
300 ) -> 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>)>)
301 where
302 FA: InferableBrand_cdc7cd43dac7585f,
303 <FA as InferableBrand_cdc7cd43dac7585f>::Brand: WithIndex, {
304 func.dispatch(ta)
305 }
306
307 pub mod explicit {
314 use super::*;
315
316 #[document_signature]
337 #[document_type_parameters(
339 "The lifetime of the values.",
340 "The brand of the cloneable function to use.",
341 "The brand of the traversable structure.",
342 "The type of the elements in the input structure.",
343 "The type of the elements in the output structure.",
344 "The applicative functor brand.",
345 "The container type (owned or borrowed), inferred from the argument.",
346 "Dispatch marker type, inferred automatically."
347 )]
348 #[document_parameters(
350 "The indexed function to apply to each element, returning a value in an applicative context.",
351 "The traversable structure (owned for Val, borrowed for Ref)."
352 )]
353 #[document_returns("The structure wrapped in the applicative context.")]
355 #[document_examples]
357 pub fn traverse_with_index<
380 'a,
381 FnBrand,
382 Brand: Kind_cdc7cd43dac7585f + WithIndex,
383 A: 'a,
384 B: 'a,
385 F: Kind_cdc7cd43dac7585f,
386 FTA,
387 Marker,
388 >(
389 func: impl TraverseWithIndexDispatch<'a, FnBrand, Brand, A, B, F, FTA, Marker>,
390 ta: FTA,
391 ) -> 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>)>)
392 {
393 func.dispatch(ta)
394 }
395 }
396}
397
398pub use inner::*;