1#[fp_macros::document_module]
38pub(crate) mod inner {
39 use {
40 crate::{
41 classes::{
42 Applicative,
43 LiftFn,
44 RefWitherable,
45 Witherable,
46 },
47 dispatch::{
48 Ref,
49 Val,
50 },
51 kinds::*,
52 },
53 fp_macros::*,
54 };
55
56 #[document_type_parameters(
65 "The lifetime of the values.",
66 "The brand of the cloneable function to use.",
67 "The brand of the witherable structure.",
68 "The applicative functor brand for the computation.",
69 "The type of the elements in the input structure.",
70 "The error type.",
71 "The success type.",
72 "The container type (owned or borrowed), inferred from the argument.",
73 "Dispatch marker type, inferred automatically. Either [`Val`](crate::dispatch::Val) or [`Ref`](crate::dispatch::Ref)."
74 )]
75 #[document_parameters("The closure implementing this dispatch.")]
76 pub trait WiltDispatch<
77 'a,
78 FnBrand,
79 Brand: Kind_cdc7cd43dac7585f,
80 M: Kind_cdc7cd43dac7585f,
81 A: 'a,
82 E: 'a,
83 O: 'a,
84 FA,
85 Marker,
86 > {
87 #[document_signature]
89 #[document_parameters("The structure to partition.")]
91 #[document_returns("The partitioned result in the applicative context.")]
93 #[document_examples]
94 fn dispatch(
109 self,
110 ta: FA,
111 ) -> Apply!(<M as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<
112 'a,
113 (
114 Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, E>),
115 Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, O>),
116 ),
117 >);
118 }
119
120 #[document_type_parameters(
122 "The lifetime of the values.",
123 "The cloneable function brand (unused by Val path).",
124 "The brand of the witherable structure.",
125 "The applicative functor brand.",
126 "The type of the elements in the input structure.",
127 "The error type.",
128 "The success type.",
129 "The closure type."
130 )]
131 #[document_parameters("The closure that takes owned values.")]
132 impl<'a, FnBrand, Brand, M, A, E, O, Func>
133 WiltDispatch<
134 'a,
135 FnBrand,
136 Brand,
137 M,
138 A,
139 E,
140 O,
141 Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, A>),
142 Val,
143 > for Func
144 where
145 Brand: Witherable,
146 A: 'a + Clone,
147 E: 'a + Clone,
148 O: 'a + Clone,
149 M: Applicative,
150 Func: Fn(A) -> Apply!(<M as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, Result<O, E>>) + 'a,
151 Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, Result<O, E>>): Clone,
152 Apply!(<M as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, Result<O, E>>): Clone,
153 {
154 #[document_signature]
155 #[document_parameters("The structure to partition.")]
157 #[document_returns("The partitioned result in the applicative context.")]
159 #[document_examples]
160 fn dispatch(
175 self,
176 ta: Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, A>),
177 ) -> Apply!(<M as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<
178 'a,
179 (
180 Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, E>),
181 Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, O>),
182 ),
183 >) {
184 Brand::wilt::<M, A, E, O>(self, ta)
185 }
186 }
187
188 #[document_type_parameters(
192 "The lifetime of the values.",
193 "The borrow lifetime.",
194 "The cloneable function brand.",
195 "The brand of the witherable structure.",
196 "The applicative functor brand.",
197 "The type of the elements in the input structure.",
198 "The error type.",
199 "The success type.",
200 "The closure type."
201 )]
202 #[document_parameters("The closure that takes references.")]
203 impl<'a, 'b, FnBrand, Brand, M, A, E, O, Func>
204 WiltDispatch<
205 'a,
206 FnBrand,
207 Brand,
208 M,
209 A,
210 E,
211 O,
212 &'b Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, A>),
213 Ref,
214 > for Func
215 where
216 Brand: RefWitherable,
217 FnBrand: LiftFn + 'a,
218 A: 'a + Clone,
219 E: 'a + Clone,
220 O: 'a + Clone,
221 M: Applicative,
222 Func: Fn(&A) -> Apply!(<M as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, Result<O, E>>) + 'a,
223 Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, Result<O, E>>): Clone,
224 Apply!(<M as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, Result<O, E>>): Clone,
225 {
226 #[document_signature]
227 #[document_parameters("A reference to the structure to partition.")]
229 #[document_returns("The partitioned result in the applicative context.")]
231 #[document_examples]
232 fn dispatch(
249 self,
250 ta: &'b Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, A>),
251 ) -> Apply!(<M as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<
252 'a,
253 (
254 Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, E>),
255 Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, O>),
256 ),
257 >) {
258 Brand::ref_wilt::<FnBrand, M, A, E, O>(self, ta)
259 }
260 }
261
262 #[document_type_parameters(
271 "The lifetime of the values.",
272 "The brand of the cloneable function to use.",
273 "The brand of the witherable structure.",
274 "The applicative functor brand for the computation.",
275 "The type of the elements in the input structure.",
276 "The type of the elements in the output structure.",
277 "The container type (owned or borrowed), inferred from the argument.",
278 "Dispatch marker type, inferred automatically. Either [`Val`](crate::dispatch::Val) or [`Ref`](crate::dispatch::Ref)."
279 )]
280 #[document_parameters("The closure implementing this dispatch.")]
281 pub trait WitherDispatch<
282 'a,
283 FnBrand,
284 Brand: Kind_cdc7cd43dac7585f,
285 M: Kind_cdc7cd43dac7585f,
286 A: 'a,
287 B: 'a,
288 FA,
289 Marker,
290 > {
291 #[document_signature]
293 #[document_parameters("The structure to filter.")]
295 #[document_returns("The filtered result in the applicative context.")]
297 #[document_examples]
298 fn dispatch(
312 self,
313 ta: FA,
314 ) -> Apply!(<M as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<
315 'a,
316 Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, B>),
317 >);
318 }
319
320 #[document_type_parameters(
322 "The lifetime of the values.",
323 "The cloneable function brand (unused by Val path).",
324 "The brand of the witherable structure.",
325 "The applicative functor brand.",
326 "The type of the elements in the input structure.",
327 "The type of the elements in the output structure.",
328 "The closure type."
329 )]
330 #[document_parameters("The closure that takes owned values.")]
331 impl<'a, FnBrand, Brand, M, A, B, Func>
332 WitherDispatch<
333 'a,
334 FnBrand,
335 Brand,
336 M,
337 A,
338 B,
339 Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, A>),
340 Val,
341 > for Func
342 where
343 Brand: Witherable,
344 A: 'a + Clone,
345 B: 'a + Clone,
346 M: Applicative,
347 Func: Fn(A) -> Apply!(<M as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, Option<B>>) + 'a,
348 Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, Option<B>>): Clone,
349 Apply!(<M as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, Option<B>>): Clone,
350 {
351 #[document_signature]
352 #[document_parameters("The structure to filter.")]
354 #[document_returns("The filtered result in the applicative context.")]
356 #[document_examples]
357 fn dispatch(
371 self,
372 ta: Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, A>),
373 ) -> Apply!(<M as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<
374 'a,
375 Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, B>),
376 >) {
377 Brand::wither::<M, A, B>(self, ta)
378 }
379 }
380
381 #[document_type_parameters(
385 "The lifetime of the values.",
386 "The borrow lifetime.",
387 "The cloneable function brand.",
388 "The brand of the witherable structure.",
389 "The applicative functor brand.",
390 "The type of the elements in the input structure.",
391 "The type of the elements in the output structure.",
392 "The closure type."
393 )]
394 #[document_parameters("The closure that takes references.")]
395 impl<'a, 'b, FnBrand, Brand, M, A, B, Func>
396 WitherDispatch<
397 'a,
398 FnBrand,
399 Brand,
400 M,
401 A,
402 B,
403 &'b Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, A>),
404 Ref,
405 > for Func
406 where
407 Brand: RefWitherable,
408 FnBrand: LiftFn + 'a,
409 A: 'a + Clone,
410 B: 'a + Clone,
411 M: Applicative,
412 Func: Fn(&A) -> Apply!(<M as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, Option<B>>) + 'a,
413 Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, Option<B>>): Clone,
414 Apply!(<M as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, Option<B>>): Clone,
415 {
416 #[document_signature]
417 #[document_parameters("A reference to the structure to filter.")]
419 #[document_returns("The filtered result in the applicative context.")]
421 #[document_examples]
422 fn dispatch(
437 self,
438 ta: &'b Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, A>),
439 ) -> Apply!(<M as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<
440 'a,
441 Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, B>),
442 >) {
443 Brand::ref_wither::<FnBrand, M, A, B>(self, ta)
444 }
445 }
446
447 #[document_signature]
460 #[document_type_parameters(
462 "The lifetime of the values.",
463 "The brand of the cloneable function to use (must be specified explicitly).",
464 "The container type (owned or borrowed). Brand is inferred from this.",
465 "The applicative functor brand (must be specified explicitly).",
466 "The type of the elements in the input structure.",
467 "The error type.",
468 "The success type.",
469 "The brand, inferred via InferableBrand from FA and the closure's input type."
470 )]
471 #[document_parameters(
473 "The function to apply to each element, returning a Result in an applicative context.",
474 "The witherable structure (owned for Val, borrowed for Ref)."
475 )]
476 #[document_returns("The partitioned structure wrapped in the applicative context.")]
478 #[document_examples]
479 pub fn wilt<'a, FnBrand, FA, M: Kind_cdc7cd43dac7585f, A: 'a, E: 'a, O: 'a, Brand>(
493 func: impl WiltDispatch<
494 'a,
495 FnBrand,
496 Brand,
497 M,
498 A,
499 E,
500 O,
501 FA,
502 <FA as InferableBrand_cdc7cd43dac7585f<'a, Brand, A>>::Marker,
503 >,
504 ta: FA,
505 ) -> Apply!(<M as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<
506 'a,
507 (
508 Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, E>),
509 Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, O>),
510 ),
511 >)
512 where
513 Brand: Kind_cdc7cd43dac7585f,
514 FA: InferableBrand_cdc7cd43dac7585f<'a, Brand, A>, {
515 func.dispatch(ta)
516 }
517
518 #[document_signature]
529 #[document_type_parameters(
531 "The lifetime of the values.",
532 "The brand of the cloneable function to use (must be specified explicitly).",
533 "The container type (owned or borrowed). Brand is inferred from this.",
534 "The applicative functor brand (must be specified explicitly).",
535 "The type of the elements in the input structure.",
536 "The type of the elements in the output structure.",
537 "The brand, inferred via InferableBrand from FA and the closure's input type."
538 )]
539 #[document_parameters(
541 "The function to apply to each element, returning an Option in an applicative context.",
542 "The witherable structure (owned for Val, borrowed for Ref)."
543 )]
544 #[document_returns("The filtered structure wrapped in the applicative context.")]
546 #[document_examples]
547 pub fn wither<'a, FnBrand, FA, M: Kind_cdc7cd43dac7585f, A: 'a, B: 'a, Brand>(
561 func: impl WitherDispatch<
562 'a,
563 FnBrand,
564 Brand,
565 M,
566 A,
567 B,
568 FA,
569 <FA as InferableBrand_cdc7cd43dac7585f<'a, Brand, A>>::Marker,
570 >,
571 ta: FA,
572 ) -> Apply!(<M as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<
573 'a,
574 Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, B>),
575 >)
576 where
577 Brand: Kind_cdc7cd43dac7585f,
578 FA: InferableBrand_cdc7cd43dac7585f<'a, Brand, A>, {
579 func.dispatch(ta)
580 }
581
582 pub mod explicit {
589 use super::*;
590
591 #[document_signature]
598 #[document_type_parameters(
600 "The lifetime of the values.",
601 "The brand of the cloneable function to use.",
602 "The brand of the witherable structure.",
603 "The applicative functor brand for the computation.",
604 "The type of the elements in the input structure.",
605 "The error type.",
606 "The success type.",
607 "The container type (owned or borrowed), inferred from the argument.",
608 "Dispatch marker type, inferred automatically."
609 )]
610 #[document_parameters(
612 "The function to apply to each element, returning a Result in an applicative context.",
613 "The witherable structure (owned for Val, borrowed for Ref)."
614 )]
615 #[document_returns("The partitioned structure wrapped in the applicative context.")]
617 #[document_examples]
619 pub fn wilt<
634 'a,
635 FnBrand,
636 Brand: Kind_cdc7cd43dac7585f,
637 M: Kind_cdc7cd43dac7585f,
638 A: 'a,
639 E: 'a,
640 O: 'a,
641 FA,
642 Marker,
643 >(
644 func: impl WiltDispatch<'a, FnBrand, Brand, M, A, E, O, FA, Marker>,
645 ta: FA,
646 ) -> Apply!(<M as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<
647 'a,
648 (
649 Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, E>),
650 Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, O>),
651 ),
652 >) {
653 func.dispatch(ta)
654 }
655
656 #[document_signature]
663 #[document_type_parameters(
665 "The lifetime of the values.",
666 "The brand of the cloneable function to use.",
667 "The brand of the witherable structure.",
668 "The applicative functor brand for the computation.",
669 "The type of the elements in the input structure.",
670 "The type of the elements in the output structure.",
671 "The container type (owned or borrowed), inferred from the argument.",
672 "Dispatch marker type, inferred automatically."
673 )]
674 #[document_parameters(
676 "The function to apply to each element, returning an Option in an applicative context.",
677 "The witherable structure (owned for Val, borrowed for Ref)."
678 )]
679 #[document_returns("The filtered structure wrapped in the applicative context.")]
681 #[document_examples]
683 pub fn wither<
697 'a,
698 FnBrand,
699 Brand: Kind_cdc7cd43dac7585f,
700 M: Kind_cdc7cd43dac7585f,
701 A: 'a,
702 B: 'a,
703 FA,
704 Marker,
705 >(
706 func: impl WitherDispatch<'a, FnBrand, Brand, M, A, B, FA, Marker>,
707 ta: FA,
708 ) -> Apply!(<M as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<
709 'a,
710 Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, B>),
711 >) {
712 func.dispatch(ta)
713 }
714 }
715}
716
717pub use inner::*;