1#[fp_macros::document_module]
28pub(crate) mod inner {
29 use {
30 crate::{
31 classes::{
32 Bifunctor,
33 RefBifunctor,
34 },
35 dispatch::{
36 Ref,
37 Val,
38 },
39 kinds::*,
40 },
41 fp_macros::*,
42 };
43
44 #[document_type_parameters(
52 "The lifetime of the values.",
53 "The brand of the bifunctor.",
54 "The type of the first value.",
55 "The type of the first result.",
56 "The type of the second value.",
57 "The type of the second result.",
58 "The container type (owned or borrowed), inferred from the argument.",
59 "Dispatch marker type, inferred automatically."
60 )]
61 #[document_parameters("The closure tuple implementing this dispatch.")]
62 pub trait BimapDispatch<
63 'a,
64 Brand: Kind_266801a817966495,
65 A: 'a,
66 B: 'a,
67 C: 'a,
68 D: 'a,
69 FA,
70 Marker,
71 > {
72 #[document_signature]
74 #[document_parameters("The bifunctor value.")]
75 #[document_returns("The result of bimapping.")]
76 #[document_examples]
77 fn dispatch(
88 self,
89 fa: FA,
90 ) -> Apply!(<Brand as Kind!( type Of<'a, A: 'a, B: 'a>: 'a; )>::Of<'a, B, D>);
91 }
92
93 #[document_type_parameters(
95 "The lifetime.",
96 "The brand.",
97 "The first input type.",
98 "The first output type.",
99 "The second input type.",
100 "The second output type.",
101 "The first closure type.",
102 "The second closure type."
103 )]
104 #[document_parameters("The closure tuple.")]
105 impl<'a, Brand, A, B, C, D, F, G>
106 BimapDispatch<
107 'a,
108 Brand,
109 A,
110 B,
111 C,
112 D,
113 Apply!(<Brand as Kind!( type Of<'a, A: 'a, B: 'a>: 'a; )>::Of<'a, A, C>),
114 Val,
115 > for (F, G)
116 where
117 Brand: Bifunctor,
118 A: 'a,
119 B: 'a,
120 C: 'a,
121 D: 'a,
122 F: Fn(A) -> B + 'a,
123 G: Fn(C) -> D + 'a,
124 {
125 #[document_signature]
126 #[document_parameters("The bifunctor value.")]
127 #[document_returns("The result of bimapping.")]
128 #[document_examples]
129 fn dispatch(
140 self,
141 fa: Apply!(<Brand as Kind!( type Of<'a, A: 'a, B: 'a>: 'a; )>::Of<'a, A, C>),
142 ) -> Apply!(<Brand as Kind!( type Of<'a, A: 'a, B: 'a>: 'a; )>::Of<'a, B, D>) {
143 Brand::bimap(self.0, self.1, fa)
144 }
145 }
146
147 #[document_type_parameters(
151 "The lifetime.",
152 "The borrow lifetime.",
153 "The brand.",
154 "The first input type.",
155 "The first output type.",
156 "The second input type.",
157 "The second output type.",
158 "The first closure type.",
159 "The second closure type."
160 )]
161 #[document_parameters("The closure tuple.")]
162 impl<'a, 'b, Brand, A, B, C, D, F, G>
163 BimapDispatch<
164 'a,
165 Brand,
166 A,
167 B,
168 C,
169 D,
170 &'b Apply!(<Brand as Kind!( type Of<'a, A: 'a, B: 'a>: 'a; )>::Of<'a, A, C>),
171 Ref,
172 > for (F, G)
173 where
174 Brand: RefBifunctor,
175 A: 'a,
176 B: 'a,
177 C: 'a,
178 D: 'a,
179 F: Fn(&A) -> B + 'a,
180 G: Fn(&C) -> D + 'a,
181 {
182 #[document_signature]
183 #[document_parameters("A reference to the bifunctor value.")]
184 #[document_returns("The result of bimapping.")]
185 #[document_examples]
186 fn dispatch(
197 self,
198 fa: &'b Apply!(<Brand as Kind!( type Of<'a, A: 'a, B: 'a>: 'a; )>::Of<'a, A, C>),
199 ) -> Apply!(<Brand as Kind!( type Of<'a, A: 'a, B: 'a>: 'a; )>::Of<'a, B, D>) {
200 Brand::ref_bimap(self.0, self.1, fa)
201 }
202 }
203
204 #[document_signature]
216 #[document_type_parameters(
218 "The lifetime of the values.",
219 "The container type (owned or borrowed). Brand is inferred from this.",
220 "The type of the first value.",
221 "The type of the first result.",
222 "The type of the second value.",
223 "The type of the second result.",
224 "The brand, inferred via InferableBrand from FA and the closure's input type."
225 )]
226 #[document_parameters(
228 "A tuple of (first function, second function).",
229 "The bifunctor value (owned for Val, borrowed for Ref)."
230 )]
231 #[document_returns(
233 "A new bifunctor instance containing the results of applying the functions."
234 )]
235 #[document_examples]
236 pub fn bimap<'a, FA, A: 'a, B: 'a, C: 'a, D: 'a, Brand>(
251 fg: impl BimapDispatch<
252 'a,
253 Brand,
254 A,
255 B,
256 C,
257 D,
258 FA,
259 <FA as InferableBrand_266801a817966495<'a, Brand, A, C>>::Marker,
260 >,
261 p: FA,
262 ) -> Apply!(<Brand as Kind!( type Of<'a, A: 'a, B: 'a>: 'a; )>::Of<'a, B, D>)
263 where
264 Brand: Kind_266801a817966495,
265 FA: InferableBrand_266801a817966495<'a, Brand, A, C>, {
266 fg.dispatch(p)
267 }
268
269 pub mod explicit {
276 use super::*;
277
278 #[document_signature]
288 #[document_type_parameters(
290 "The lifetime of the values.",
291 "The brand of the bifunctor.",
292 "The type of the first value.",
293 "The type of the first result.",
294 "The type of the second value.",
295 "The type of the second result.",
296 "The container type (owned or borrowed), inferred from the argument.",
297 "Dispatch marker type, inferred automatically."
298 )]
299 #[document_parameters(
301 "A tuple of (first function, second function).",
302 "The bifunctor value (owned for Val, borrowed for Ref)."
303 )]
304 #[document_returns(
306 "A new bifunctor instance containing the results of applying the functions."
307 )]
308 #[document_examples]
309 pub fn bimap<'a, Brand: Kind_266801a817966495, A: 'a, B: 'a, C: 'a, D: 'a, FA, Marker>(
327 fg: impl BimapDispatch<'a, Brand, A, B, C, D, FA, Marker>,
328 p: FA,
329 ) -> Apply!(<Brand as Kind!( type Of<'a, A: 'a, B: 'a>: 'a; )>::Of<'a, B, D>) {
330 fg.dispatch(p)
331 }
332 }
333}
334
335pub use inner::*;