1#[fp_macros::document_module]
28pub(crate) mod inner {
29 use {
30 crate::{
31 classes::{
32 ApplyFirst,
33 RefApplyFirst,
34 },
35 dispatch::{
36 Ref,
37 Val,
38 },
39 kinds::*,
40 },
41 fp_macros::*,
42 };
43
44 #[document_type_parameters(
50 "The lifetime of the values.",
51 "The brand of the applicative.",
52 "The type of the value(s) inside the first container.",
53 "The type of the value(s) inside the second container.",
54 "Dispatch marker type, inferred automatically. Either [`Val`](crate::dispatch::Val) or [`Ref`](crate::dispatch::Ref)."
55 )]
56 #[document_parameters("The first container implementing this dispatch.")]
57 pub trait ApplyFirstDispatch<'a, Brand: Kind_cdc7cd43dac7585f, A: 'a, B: 'a, Marker> {
58 type FB;
60
61 #[document_signature]
63 #[document_parameters("The second container (its result is discarded).")]
65 #[document_returns("A container preserving the values from the first input.")]
67 #[document_examples]
68 fn dispatch(
79 self,
80 fb: Self::FB,
81 ) -> Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, A>);
82 }
83
84 #[document_type_parameters(
88 "The lifetime of the values.",
89 "The brand of the applicative.",
90 "The type of the value(s) inside the first container.",
91 "The type of the value(s) inside the second container."
92 )]
93 #[document_parameters("The owned first container.")]
94 impl<'a, Brand, A, B> ApplyFirstDispatch<'a, Brand, A, B, Val> for Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, A>)
95 where
96 Brand: ApplyFirst,
97 A: 'a + Clone,
98 B: 'a + Clone,
99 {
100 type FB = Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, B>);
101
102 #[document_signature]
103 #[document_parameters("The second container (its result is discarded).")]
105 #[document_returns("A container preserving the values from the first input.")]
107 #[document_examples]
108 fn dispatch(
119 self,
120 fb: Self::FB,
121 ) -> Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, A>) {
122 Brand::apply_first(self, fb)
123 }
124 }
125
126 #[document_type_parameters(
130 "The lifetime of the values.",
131 "The borrow lifetime.",
132 "The brand of the applicative.",
133 "The type of the value(s) inside the first container.",
134 "The type of the value(s) inside the second container."
135 )]
136 #[document_parameters("The borrowed first container.")]
137 impl<'a, 'b, Brand, A, B> ApplyFirstDispatch<'a, Brand, A, B, Ref> for &'b Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, A>)
138 where
139 'a: 'b,
140 Brand: RefApplyFirst,
141 A: 'a + Clone,
142 B: 'a,
143 {
144 type FB = &'b Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, B>);
145
146 #[document_signature]
147 #[document_parameters("The second borrowed container (its result is discarded).")]
149 #[document_returns("A container preserving the values from the first input.")]
151 #[document_examples]
152 fn dispatch(
165 self,
166 fb: Self::FB,
167 ) -> Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, A>) {
168 Brand::ref_apply_first(self, fb)
169 }
170 }
171
172 #[document_signature]
183 #[document_type_parameters(
185 "The lifetime of the values.",
186 "The first container type (owned or borrowed). Brand is inferred from this.",
187 "The type of the value(s) inside the first container.",
188 "The type of the value(s) inside the second container.",
189 "The brand, inferred via InferableBrand from FA and the element type."
190 )]
191 #[document_parameters(
193 "The first container (its values are preserved).",
194 "The second container (its values are discarded)."
195 )]
196 #[document_returns("A container preserving the values from the first input.")]
198 #[document_examples]
199 pub fn apply_first<'a, FA, A: 'a, B: 'a, Brand>(
210 fa: FA,
211 fb: <FA as ApplyFirstDispatch<
212 'a,
213 Brand,
214 A,
215 B,
216 <FA as InferableBrand_cdc7cd43dac7585f<'a, Brand, A>>::Marker,
217 >>::FB,
218 ) -> <Brand as Kind_cdc7cd43dac7585f>::Of<'a, A>
219 where
220 Brand: Kind_cdc7cd43dac7585f,
221 FA: InferableBrand_cdc7cd43dac7585f<'a, Brand, A>
222 + ApplyFirstDispatch<
223 'a,
224 Brand,
225 A,
226 B,
227 <FA as InferableBrand_cdc7cd43dac7585f<'a, Brand, A>>::Marker,
228 >, {
229 fa.dispatch(fb)
230 }
231
232 pub mod explicit {
239 use super::*;
240
241 #[document_signature]
254 #[document_type_parameters(
256 "The lifetime of the values.",
257 "The brand of the applicative.",
258 "The type of the value(s) inside the first container.",
259 "The type of the value(s) inside the second container.",
260 "The first container type (owned or borrowed), inferred from the argument.",
261 "Dispatch marker type, inferred automatically."
262 )]
263 #[document_parameters(
265 "The first container (its values are preserved).",
266 "The second container (its values are discarded)."
267 )]
268 #[document_returns("A container preserving the values from the first input.")]
270 #[document_examples]
272 pub fn apply_first<'a, Brand: Kind_cdc7cd43dac7585f, A: 'a, B: 'a, FA, Marker>(
290 fa: FA,
291 fb: <FA as ApplyFirstDispatch<'a, Brand, A, B, Marker>>::FB,
292 ) -> Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, A>)
293 where
294 FA: ApplyFirstDispatch<'a, Brand, A, B, Marker>, {
295 fa.dispatch(fb)
296 }
297 }
298}
299
300pub use inner::*;