1#[fp_macros::document_module]
16mod inner {
17 use {
18 crate::{
19 brands::*,
20 classes::*,
21 kinds::*,
22 },
23 fp_macros::*,
24 };
25
26 pub trait Bifunctor: Kind_266801a817966495 {
49 #[document_signature]
53 #[document_type_parameters(
55 "The lifetime of the values.",
56 "The type of the first value.",
57 "The type of the first result.",
58 "The type of the second value.",
59 "The type of the second result."
60 )]
61 #[document_parameters(
63 "The function to apply to the first value.",
64 "The function to apply to the second value.",
65 "The bifunctor instance."
66 )]
67 #[document_returns(
69 "A new bifunctor instance containing the results of applying the functions."
70 )]
71 #[document_examples]
72 fn bimap<'a, A: 'a, B: 'a, C: 'a, D: 'a>(
84 f: impl Fn(A) -> B + 'a,
85 g: impl Fn(C) -> D + 'a,
86 p: Apply!(<Self as Kind!( type Of<'a, A: 'a, B: 'a>: 'a; )>::Of<'a, A, C>),
87 ) -> Apply!(<Self as Kind!( type Of<'a, A: 'a, B: 'a>: 'a; )>::Of<'a, B, D>);
88 }
89
90 #[document_signature]
94 #[document_type_parameters(
96 "The lifetime of the values.",
97 "The brand of the bifunctor.",
98 "The type of the first value.",
99 "The type of the first result.",
100 "The type of the second value.",
101 "The type of the second result."
102 )]
103 #[document_parameters(
105 "The function to apply to the first value.",
106 "The function to apply to the second value.",
107 "The bifunctor instance."
108 )]
109 #[document_returns(
111 "A new bifunctor instance containing the results of applying the functions."
112 )]
113 #[document_examples]
114 pub fn bimap<'a, Brand: Bifunctor, A: 'a, B: 'a, C: 'a, D: 'a>(
126 f: impl Fn(A) -> B + 'a,
127 g: impl Fn(C) -> D + 'a,
128 p: 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, D>) {
130 Brand::bimap(f, g, p)
131 }
132
133 impl_kind! {
134 impl<Brand: Bifunctor, A: 'static> for BifunctorFirstAppliedBrand<Brand, A> {
135 type Of<'a, B: 'a>: 'a = Apply!(<Brand as Kind!(type Of<'a, T: 'a, U: 'a>: 'a;)>::Of<'a, A, B>);
136 }
137 }
138
139 #[document_type_parameters("The bifunctor brand.", "The fixed second type parameter.")]
144 impl<Brand: Bifunctor, A: 'static> Functor for BifunctorFirstAppliedBrand<Brand, A> {
145 #[document_signature]
147 #[document_type_parameters(
148 "The lifetime of the values.",
149 "The input type.",
150 "The output type."
151 )]
152 #[document_parameters("The function to apply.", "The bifunctor value to map over.")]
153 #[document_returns("The mapped bifunctor value.")]
154 #[document_examples]
155 fn map<'a, B: 'a, C: 'a>(
167 f: impl Fn(B) -> C + 'a,
168 fa: Apply!(<Self as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, B>),
169 ) -> Apply!(<Self as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, C>) {
170 Brand::bimap(crate::functions::identity, f, fa)
171 }
172 }
173
174 impl_kind! {
175 impl<Brand: Bifunctor, B: 'static> for BifunctorSecondAppliedBrand<Brand, B> {
176 type Of<'a, A: 'a>: 'a = Apply!(<Brand as Kind!(type Of<'a, T: 'a, U: 'a>: 'a;)>::Of<'a, A, B>);
177 }
178 }
179
180 #[document_type_parameters("The bifunctor brand.", "The fixed first type parameter.")]
185 impl<Brand: Bifunctor, B: 'static> Functor for BifunctorSecondAppliedBrand<Brand, B> {
186 #[document_signature]
188 #[document_type_parameters(
189 "The lifetime of the values.",
190 "The input type.",
191 "The output type."
192 )]
193 #[document_parameters("The function to apply.", "The bifunctor value to map over.")]
194 #[document_returns("The mapped bifunctor value.")]
195 #[document_examples]
196 fn map<'a, A: 'a, C: 'a>(
208 f: impl Fn(A) -> C + 'a,
209 fa: Apply!(<Self as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, A>),
210 ) -> Apply!(<Self as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, C>) {
211 Brand::bimap(f, crate::functions::identity, fa)
212 }
213 }
214}
215
216pub use inner::*;