1pub use {
24 choice::*,
25 closed::*,
26 cochoice::*,
27 costrong::*,
28 strong::*,
29 wander::*,
30};
31
32pub mod choice;
33pub mod closed;
34pub mod cochoice;
35pub mod costrong;
36pub mod strong;
37pub mod wander;
38
39#[fp_macros::document_module]
40mod inner {
41 use {
42 crate::{
43 brands::*,
44 classes::*,
45 kinds::*,
46 },
47 fp_macros::*,
48 };
49
50 pub trait Profunctor: Kind_266801a817966495 {
75 #[document_signature]
80 #[document_type_parameters(
82 "The lifetime of the values.",
83 "The new input type (contravariant position).",
84 "The original input type.",
85 "The original output type.",
86 "The new output type (covariant position)."
87 )]
88 #[document_parameters(
90 "The contravariant function to apply to the input.",
91 "The covariant function to apply to the output.",
92 "The profunctor instance."
93 )]
94 #[document_returns("A new profunctor instance with transformed input and output types.")]
96 #[document_examples]
97 fn dimap<'a, A: 'a, B: 'a, C: 'a, D: 'a>(
114 ab: impl Fn(A) -> B + 'a,
115 cd: impl Fn(C) -> D + 'a,
116 pbc: Apply!(<Self as Kind!( type Of<'a, T: 'a, U: 'a>: 'a; )>::Of<'a, B, C>),
117 ) -> Apply!(<Self as Kind!( type Of<'a, T: 'a, U: 'a>: 'a; )>::Of<'a, A, D>);
118
119 #[document_signature]
123 #[document_type_parameters(
125 "The lifetime of the values.",
126 "The new input type.",
127 "The original input type.",
128 "The output type."
129 )]
130 #[document_parameters(
132 "The contravariant function to apply to the input.",
133 "The profunctor instance."
134 )]
135 #[document_returns("A new profunctor instance with transformed input type.")]
137 #[document_examples]
138 fn lmap<'a, A: 'a, B: 'a, C: 'a>(
154 ab: impl Fn(A) -> B + 'a,
155 pbc: Apply!(<Self as Kind!( type Of<'a, T: 'a, U: 'a>: 'a; )>::Of<'a, B, C>),
156 ) -> Apply!(<Self as Kind!( type Of<'a, T: 'a, U: 'a>: 'a; )>::Of<'a, A, C>) {
157 Self::dimap(ab, crate::functions::identity, pbc)
158 }
159
160 #[document_signature]
164 #[document_type_parameters(
166 "The lifetime of the values.",
167 "The input type.",
168 "The original output type.",
169 "The new output type."
170 )]
171 #[document_parameters(
173 "The covariant function to apply to the output.",
174 "The profunctor instance."
175 )]
176 #[document_returns("A new profunctor instance with transformed output type.")]
178 #[document_examples]
179 fn rmap<'a, A: 'a, B: 'a, C: 'a>(
195 bc: impl Fn(B) -> C + 'a,
196 pab: Apply!(<Self as Kind!( type Of<'a, T: 'a, U: 'a>: 'a; )>::Of<'a, A, B>),
197 ) -> Apply!(<Self as Kind!( type Of<'a, T: 'a, U: 'a>: 'a; )>::Of<'a, A, C>) {
198 Self::dimap(crate::functions::identity, bc, pab)
199 }
200 }
201
202 #[document_signature]
206 #[document_type_parameters(
208 "The lifetime of the values.",
209 "The brand of the profunctor.",
210 "The new input type (contravariant position).",
211 "The original input type.",
212 "The original output type.",
213 "The new output type (covariant position)."
214 )]
215 #[document_parameters(
217 "The contravariant function to apply to the input.",
218 "The covariant function to apply to the output.",
219 "The profunctor instance."
220 )]
221 #[document_returns("A new profunctor instance with transformed input and output types.")]
223 #[document_examples]
224 pub fn dimap<'a, Brand: Profunctor, A: 'a, B: 'a, C: 'a, D: 'a>(
241 ab: impl Fn(A) -> B + 'a,
242 cd: impl Fn(C) -> D + 'a,
243 pbc: Apply!(<Brand as Kind!( type Of<'a, T: 'a, U: 'a>: 'a; )>::Of<'a, B, C>),
244 ) -> Apply!(<Brand as Kind!( type Of<'a, T: 'a, U: 'a>: 'a; )>::Of<'a, A, D>) {
245 Brand::dimap(ab, cd, pbc)
246 }
247
248 #[document_signature]
252 #[document_type_parameters(
254 "The lifetime of the values.",
255 "The brand of the profunctor.",
256 "The new input type.",
257 "The original input type.",
258 "The output type."
259 )]
260 #[document_parameters(
262 "The contravariant function to apply to the input.",
263 "The profunctor instance."
264 )]
265 #[document_returns("A new profunctor instance with transformed input type.")]
267 #[document_examples]
268 pub fn lmap<'a, Brand: Profunctor, A: 'a, B: 'a, C: 'a>(
284 ab: impl Fn(A) -> B + 'a,
285 pbc: Apply!(<Brand as Kind!( type Of<'a, T: 'a, U: 'a>: 'a; )>::Of<'a, B, C>),
286 ) -> Apply!(<Brand as Kind!( type Of<'a, T: 'a, U: 'a>: 'a; )>::Of<'a, A, C>) {
287 Brand::lmap(ab, pbc)
288 }
289
290 #[document_signature]
294 #[document_type_parameters(
296 "The lifetime of the values.",
297 "The brand of the profunctor.",
298 "The input type.",
299 "The original output type.",
300 "The new output type."
301 )]
302 #[document_parameters(
304 "The covariant function to apply to the output.",
305 "The profunctor instance."
306 )]
307 #[document_returns("A new profunctor instance with transformed output type.")]
309 #[document_examples]
310 pub fn rmap<'a, Brand: Profunctor, A: 'a, B: 'a, C: 'a>(
326 bc: impl Fn(B) -> C + 'a,
327 pab: Apply!(<Brand as Kind!( type Of<'a, T: 'a, U: 'a>: 'a; )>::Of<'a, A, B>),
328 ) -> Apply!(<Brand as Kind!( type Of<'a, T: 'a, U: 'a>: 'a; )>::Of<'a, A, C>) {
329 Brand::rmap(bc, pab)
330 }
331
332 #[document_signature]
338 #[document_type_parameters(
340 "The lifetime of the function and its captured data.",
341 "The brand of the profunctor.",
342 "The input type.",
343 "The output type."
344 )]
345 #[document_parameters("The closure to lift.")]
347 #[document_returns("The lifted profunctor value.")]
349 #[document_examples]
350 pub fn arrow<'a, Brand, A, B: 'a>(
361 f: impl 'a + Fn(A) -> B
362 ) -> Apply!(<Brand as Kind!( type Of<'a, T: 'a, U: 'a>: 'a; )>::Of<'a, A, B>)
363 where
364 Brand: Category + Profunctor, {
365 Brand::rmap(f, Brand::identity())
366 }
367
368 crate::impl_kind! {
369 impl<Brand: Profunctor, A: 'static> for ProfunctorFirstAppliedBrand<Brand, A> {
370 type Of<'a, B: 'a>: 'a = Apply!(<Brand as Kind!(type Of<'a, T: 'a, U: 'a>: 'a;)>::Of<'a, A, B>);
371 }
372 }
373
374 #[document_type_parameters("The profunctor brand.", "The fixed first type parameter.")]
378 impl<Brand: Profunctor, A: 'static> Functor for ProfunctorFirstAppliedBrand<Brand, A> {
379 #[document_signature]
381 #[document_type_parameters(
382 "The lifetime of the values.",
383 "The input type.",
384 "The output type."
385 )]
386 #[document_parameters("The function to apply.", "The profunctor value to map over.")]
387 #[document_returns("The mapped profunctor value.")]
388 #[document_examples]
389 fn map<'a, B: 'a, C: 'a>(
401 f: impl Fn(B) -> C + 'a,
402 fa: Apply!(<Self as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, B>),
403 ) -> Apply!(<Self as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, C>) {
404 Brand::rmap(f, fa)
405 }
406 }
407
408 impl_kind! {
409 impl<Brand: Profunctor, B: 'static> for ProfunctorSecondAppliedBrand<Brand, B> {
410 type Of<'a, A: 'a>: 'a = Apply!(<Brand as Kind!(type Of<'a, T: 'a, U: 'a>: 'a;)>::Of<'a, A, B>);
411 }
412 }
413
414 #[document_type_parameters("The profunctor brand.", "The fixed second type parameter.")]
418 impl<Brand: Profunctor, B: 'static> Contravariant for ProfunctorSecondAppliedBrand<Brand, B> {
419 #[document_signature]
421 #[document_type_parameters(
422 "The lifetime of the values.",
423 "The input type.",
424 "The output type."
425 )]
426 #[document_parameters("The function to apply.", "The profunctor value to contramap over.")]
427 #[document_returns("The contramapped profunctor value.")]
428 #[document_examples]
429 fn contramap<'a, A: 'a, C: 'a>(
441 f: impl Fn(C) -> A + 'a,
442 fa: Apply!(<Self as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, A>),
443 ) -> Apply!(<Self as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, C>) {
444 Brand::lmap(f, fa)
445 }
446 }
447}
448
449pub use inner::*;