1#[fp_macros::document_module]
30pub(crate) mod inner {
31 use {
32 crate::{
33 classes::{
34 Bifunctor,
35 RefBifunctor,
36 },
37 dispatch::{
38 Ref,
39 Val,
40 },
41 kinds::*,
42 },
43 fp_macros::*,
44 };
45
46 #[document_type_parameters(
54 "The lifetime of the values.",
55 "The brand of the bifunctor.",
56 "The type of the first value.",
57 "The type of the first result.",
58 "The type of the second value.",
59 "The container type (owned or borrowed), inferred from the argument.",
60 "Dispatch marker type, inferred automatically."
61 )]
62 #[document_parameters("The closure implementing this dispatch.")]
63 pub trait MapFirstDispatch<'a, Brand: Kind_266801a817966495, A: 'a, B: 'a, C: 'a, FA, Marker> {
64 #[document_signature]
66 #[document_parameters("The bifunctor value.")]
67 #[document_returns("A new bifunctor with the first value transformed.")]
68 #[document_examples]
69 fn dispatch(
79 self,
80 fa: FA,
81 ) -> Apply!(<Brand as Kind!( type Of<'a, A: 'a, B: 'a>: 'a; )>::Of<'a, B, C>);
82 }
83
84 #[document_type_parameters(
88 "The lifetime of the values.",
89 "The brand of the bifunctor.",
90 "The type of the first value.",
91 "The type of the first result.",
92 "The type of the second value.",
93 "The closure type."
94 )]
95 #[document_parameters("The closure that takes owned values.")]
96 impl<'a, Brand, A, B, C, F>
97 MapFirstDispatch<
98 'a,
99 Brand,
100 A,
101 B,
102 C,
103 Apply!(<Brand as Kind!( type Of<'a, A: 'a, B: 'a>: 'a; )>::Of<'a, A, C>),
104 Val,
105 > for F
106 where
107 Brand: Bifunctor,
108 A: 'a,
109 B: 'a,
110 C: 'a,
111 F: Fn(A) -> B + 'a,
112 {
113 #[document_signature]
114 #[document_parameters("The bifunctor value.")]
115 #[document_returns("A new bifunctor with the first value transformed.")]
116 #[document_examples]
117 fn dispatch(
127 self,
128 fa: Apply!(<Brand as Kind!( type Of<'a, A: 'a, B: 'a>: 'a; )>::Of<'a, A, C>),
129 ) -> Apply!(<Brand as Kind!( type Of<'a, A: 'a, B: 'a>: 'a; )>::Of<'a, B, C>) {
130 Brand::map_first(self, fa)
131 }
132 }
133
134 #[document_type_parameters(
140 "The lifetime of the values.",
141 "The borrow lifetime.",
142 "The brand of the bifunctor.",
143 "The type of the first value.",
144 "The type of the first result.",
145 "The type of the second value (must be Clone).",
146 "The closure type."
147 )]
148 #[document_parameters("The closure that takes references.")]
149 impl<'a, 'b, Brand, A, B, C, F>
150 MapFirstDispatch<
151 'a,
152 Brand,
153 A,
154 B,
155 C,
156 &'b Apply!(<Brand as Kind!( type Of<'a, A: 'a, B: 'a>: 'a; )>::Of<'a, A, C>),
157 Ref,
158 > for F
159 where
160 Brand: RefBifunctor,
161 A: 'a,
162 B: 'a,
163 C: Clone + 'a,
164 F: Fn(&A) -> B + 'a,
165 {
166 #[document_signature]
167 #[document_parameters("A reference to the bifunctor value.")]
168 #[document_returns("A new bifunctor with the first value transformed.")]
169 #[document_examples]
170 fn dispatch(
181 self,
182 fa: &'b Apply!(<Brand as Kind!( type Of<'a, A: 'a, B: 'a>: 'a; )>::Of<'a, A, C>),
183 ) -> Apply!(<Brand as Kind!( type Of<'a, A: 'a, B: 'a>: 'a; )>::Of<'a, B, C>) {
184 Brand::ref_map_first(self, fa)
185 }
186 }
187
188 #[document_signature]
202 #[document_type_parameters(
204 "The lifetime of the values.",
205 "The container type (owned or borrowed). Brand is inferred from this.",
206 "The type of the first value.",
207 "The type of the first result.",
208 "The type of the second value.",
209 "The brand, inferred via InferableBrand from FA and the element types."
210 )]
211 #[document_parameters(
213 "The function to apply to the first value.",
214 "The bifunctor value (owned or borrowed)."
215 )]
216 #[document_returns("A new bifunctor with the first value transformed.")]
218 #[document_examples]
219 pub fn map_first<'a, FA, A: 'a, B: 'a, C: 'a, Brand>(
229 f: impl MapFirstDispatch<
230 'a,
231 Brand,
232 A,
233 B,
234 C,
235 FA,
236 <FA as InferableBrand_266801a817966495<'a, Brand, A, C>>::Marker,
237 >,
238 p: FA,
239 ) -> Apply!(<Brand as Kind!( type Of<'a, A: 'a, B: 'a>: 'a; )>::Of<'a, B, C>)
240 where
241 Brand: Kind_266801a817966495,
242 FA: InferableBrand_266801a817966495<'a, Brand, A, C>, {
243 f.dispatch(p)
244 }
245
246 pub mod explicit {
253 use super::*;
254
255 #[document_signature]
266 #[document_type_parameters(
268 "The lifetime of the values.",
269 "The brand of the bifunctor.",
270 "The type of the first value.",
271 "The type of the first result.",
272 "The type of the second value.",
273 "The container type (owned or borrowed), inferred from the argument.",
274 "Dispatch marker type, inferred automatically."
275 )]
276 #[document_parameters(
278 "The function to apply to the first value.",
279 "The bifunctor value (owned for Val, borrowed for Ref)."
280 )]
281 #[document_returns("A new bifunctor with the first value transformed.")]
283 #[document_examples]
284 pub fn map_first<'a, Brand: Kind_266801a817966495, A: 'a, B: 'a, C: 'a, FA, Marker>(
302 f: impl MapFirstDispatch<'a, Brand, A, B, C, FA, Marker>,
303 p: FA,
304 ) -> Apply!(<Brand as Kind!( type Of<'a, A: 'a, B: 'a>: 'a; )>::Of<'a, B, C>) {
305 f.dispatch(p)
306 }
307 }
308}
309
310pub use inner::*;