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 "Dispatch marker type, inferred automatically."
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, Marker>(
210 fa: FA,
211 fb: <FA as ApplyFirstDispatch<
212 'a,
213 <FA as InferableBrand_cdc7cd43dac7585f>::Brand,
214 A,
215 B,
216 Marker,
217 >>::FB,
218 ) -> <<FA as InferableBrand_cdc7cd43dac7585f>::Brand as Kind_cdc7cd43dac7585f>::Of<'a, A>
219 where
220 FA: InferableBrand_cdc7cd43dac7585f
221 + ApplyFirstDispatch<'a, <FA as InferableBrand_cdc7cd43dac7585f>::Brand, A, B, Marker>, {
222 fa.dispatch(fb)
223 }
224
225 pub mod explicit {
232 use super::*;
233
234 #[document_signature]
247 #[document_type_parameters(
249 "The lifetime of the values.",
250 "The brand of the applicative.",
251 "The type of the value(s) inside the first container.",
252 "The type of the value(s) inside the second container.",
253 "The first container type (owned or borrowed), inferred from the argument.",
254 "Dispatch marker type, inferred automatically."
255 )]
256 #[document_parameters(
258 "The first container (its values are preserved).",
259 "The second container (its values are discarded)."
260 )]
261 #[document_returns("A container preserving the values from the first input.")]
263 #[document_examples]
265 pub fn apply_first<'a, Brand: Kind_cdc7cd43dac7585f, A: 'a, B: 'a, FA, Marker>(
283 fa: FA,
284 fb: <FA as ApplyFirstDispatch<'a, Brand, A, B, Marker>>::FB,
285 ) -> Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, A>)
286 where
287 FA: ApplyFirstDispatch<'a, Brand, A, B, Marker>, {
288 fa.dispatch(fb)
289 }
290 }
291}
292
293pub use inner::*;