1#[fp_macros::document_module]
31pub(crate) mod inner {
32 use {
33 crate::{
34 classes::{
35 CloneFn,
36 RefSemiapplicative,
37 Semiapplicative,
38 },
39 dispatch::{
40 ClosureMode,
41 Ref,
42 Val,
43 },
44 kinds::*,
45 },
46 fp_macros::*,
47 };
48
49 #[document_type_parameters(
60 "The function-wrapping brand (e.g., RcFnBrand, ArcFnBrand).",
61 "The input type of the wrapped function.",
62 "The output type of the wrapped function.",
63 "The closure mode (Val or Ref)."
64 )]
65 pub trait InferableFnBrand<FnBrand, A, B, Mode = Val> {}
66
67 #[document_type_parameters(
71 "The lifetime of the wrapped function.",
72 "The input type of the wrapped function.",
73 "The output type of the wrapped function."
74 )]
75 impl<'a, A: 'a, B: 'a> InferableFnBrand<crate::brands::RcFnBrand, A, B, Val>
76 for std::rc::Rc<dyn 'a + Fn(A) -> B>
77 {
78 }
79
80 #[document_type_parameters(
82 "The lifetime of the wrapped function.",
83 "The input type of the wrapped function.",
84 "The output type of the wrapped function."
85 )]
86 impl<'a, A: 'a, B: 'a> InferableFnBrand<crate::brands::RcFnBrand, A, B, Ref>
87 for std::rc::Rc<dyn 'a + Fn(&A) -> B>
88 {
89 }
90
91 #[document_type_parameters(
95 "The lifetime of the wrapped function.",
96 "The input type of the wrapped function.",
97 "The output type of the wrapped function."
98 )]
99 impl<'a, A: 'a, B: 'a> InferableFnBrand<crate::brands::ArcFnBrand, A, B, Val>
100 for std::sync::Arc<dyn 'a + Fn(A) -> B + Send + Sync>
101 {
102 }
103
104 #[document_type_parameters(
106 "The lifetime of the wrapped function.",
107 "The input type of the wrapped function.",
108 "The output type of the wrapped function."
109 )]
110 impl<'a, A: 'a, B: 'a> InferableFnBrand<crate::brands::ArcFnBrand, A, B, Ref>
111 for std::sync::Arc<dyn 'a + Fn(&A) -> B + Send + Sync>
112 {
113 }
114
115 #[document_type_parameters(
123 "The lifetime of the values.",
124 "The function-wrapping brand.",
125 "The brand of the applicative.",
126 "The type of the value(s) inside the value container.",
127 "The result type after applying the function.",
128 "The concrete wrapped-function type.",
129 "The value container type.",
130 "Dispatch marker type, inferred automatically."
131 )]
132 #[document_parameters("The function container implementing this dispatch.")]
133 pub trait ApplyDispatch<
134 'a,
135 FnBrand,
136 Brand: Kind_cdc7cd43dac7585f,
137 A: 'a,
138 B: 'a,
139 WrappedFn: 'a,
140 FA,
141 Marker,
142 > {
143 #[document_signature]
145 #[document_parameters("The value container to apply the function(s) to.")]
147 #[document_returns("A new container with the function(s) applied to the value(s).")]
149 #[document_examples]
150 fn dispatch(
163 self,
164 fa: FA,
165 ) -> Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, B>);
166 }
167
168 #[document_type_parameters(
172 "The lifetime of the values.",
173 "The function-wrapping brand.",
174 "The brand of the applicative.",
175 "The type of the value(s) inside the value container.",
176 "The result type after applying the function.",
177 "The concrete wrapped-function type."
178 )]
179 #[document_parameters("The owned function container.")]
180 impl<'a, FnBrand, Brand, A, B, WrappedFn>
181 ApplyDispatch<
182 'a,
183 FnBrand,
184 Brand,
185 A,
186 B,
187 WrappedFn,
188 Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, A>),
189 Val,
190 > for Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, WrappedFn>)
191 where
192 FnBrand: CloneFn + 'a,
193 Brand: Semiapplicative,
194 A: Clone + 'a,
195 B: 'a,
196 WrappedFn: Clone + 'a,
197 Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, WrappedFn>): Into<
198 Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, <FnBrand as CloneFn>::Of<'a, A, B>>),
199 >,
200 {
201 #[document_signature]
202 #[document_parameters("The value container to apply the function(s) to.")]
204 #[document_returns("A new container with the function(s) applied to the value(s).")]
206 #[document_examples]
207 fn dispatch(
220 self,
221 fa: Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, A>),
222 ) -> Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, B>) {
223 Brand::apply::<FnBrand, A, B>(self.into(), fa)
224 }
225 }
226
227 #[document_type_parameters(
231 "The lifetime of the values.",
232 "The borrow lifetime.",
233 "The function-wrapping brand.",
234 "The brand of the applicative.",
235 "The type of the value(s) inside the value container.",
236 "The result type after applying the function.",
237 "The concrete wrapped-function type."
238 )]
239 #[document_parameters("The borrowed function container.")]
240 impl<'a, 'b, FnBrand, Brand, A, B, WrappedFn>
241 ApplyDispatch<
242 'a,
243 FnBrand,
244 Brand,
245 A,
246 B,
247 WrappedFn,
248 &'b Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, A>),
249 Ref,
250 > for &'b Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, WrappedFn>)
251 where
252 'a: 'b,
253 FnBrand: CloneFn<Ref> + 'a,
254 Brand: RefSemiapplicative,
255 A: 'a,
256 B: 'a,
257 WrappedFn: 'a,
258 &'b Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, WrappedFn>): Into<
259 &'b Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, <FnBrand as CloneFn<Ref>>::Of<'a, A, B>>),
260 >,
261 {
262 #[document_signature]
263 #[document_parameters("The borrowed value container to apply the function(s) to.")]
265 #[document_returns("A new container with the function(s) applied to the value(s).")]
267 #[document_examples]
268 fn dispatch(
281 self,
282 fa: &'b Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, A>),
283 ) -> Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, B>) {
284 Brand::ref_apply::<FnBrand, A, B>(self.into(), fa)
285 }
286 }
287
288 #[document_signature]
303 #[document_type_parameters(
305 "The lifetime of the values.",
306 "The function-wrapping brand, inferred via InferableFnBrand.",
307 "The brand, inferred via InferableBrand from FF and FA.",
308 "The type of the value(s) inside the value container.",
309 "The result type after applying the function.",
310 "The concrete wrapped-function type, inferred from FF's element type.",
311 "The function container type.",
312 "The value container type."
313 )]
314 #[document_parameters(
316 "The container of function(s) to apply.",
317 "The container of value(s) to apply the function(s) to."
318 )]
319 #[document_returns("A new container with the function(s) applied to the value(s).")]
321 #[document_examples]
322 #[allow_named_generics]
342 pub fn apply<'a, FnBrand, Brand, A, B, WrappedFn, FF, FA>(
343 ff: FF,
344 fa: FA,
345 ) -> Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, B>)
346 where
347 Brand: Kind_cdc7cd43dac7585f,
348 A: 'a,
349 B: 'a,
350 WrappedFn: 'a,
351 FA: InferableBrand_cdc7cd43dac7585f<'a, Brand, A>,
352 <FA as InferableBrand_cdc7cd43dac7585f<'a, Brand, A>>::Marker: ClosureMode,
353 FnBrand: CloneFn<<FA as InferableBrand_cdc7cd43dac7585f<'a, Brand, A>>::Marker> + 'a,
354 WrappedFn: InferableFnBrand<
355 FnBrand,
356 A,
357 B,
358 <FA as InferableBrand_cdc7cd43dac7585f<'a, Brand, A>>::Marker,
359 >,
360 FF: InferableBrand_cdc7cd43dac7585f<'a, Brand, WrappedFn>
361 + ApplyDispatch<
362 'a,
363 FnBrand,
364 Brand,
365 A,
366 B,
367 WrappedFn,
368 FA,
369 <FA as InferableBrand_cdc7cd43dac7585f<'a, Brand, A>>::Marker,
370 >, {
371 ff.dispatch(fa)
372 }
373}
374
375pub use inner::*;