1#[fp_macros::document_module]
6mod inner {
7 use {
8 crate::{
9 Apply,
10 brands::{
11 FnBrand,
12 optics::*,
13 },
14 classes::{
15 optics::*,
16 *,
17 },
18 kinds::*,
19 types::optics::Tagged,
20 },
21 fp_macros::*,
22 std::marker::PhantomData,
23 };
24
25 #[document_type_parameters(
29 "The lifetime of the values.",
30 "The reference-counted pointer type.",
31 "The source type of the structure.",
32 "The target type of the structure.",
33 "The source type of the focus.",
34 "The target type of the focus."
35 )]
36 pub struct Review<'a, PointerBrand, S, T, A, B>
37 where
38 PointerBrand: UnsizedCoercible,
39 S: 'a,
40 T: 'a,
41 A: 'a,
42 B: 'a, {
43 pub review_fn: Apply!(<FnBrand<PointerBrand> as Kind!( type Of<'b, U: 'b, V: 'b>: 'b; )>::Of<'a, B, T>),
45 pub(crate) _phantom: PhantomData<&'a (S, A)>,
46 }
47
48 #[document_type_parameters(
49 "The lifetime of the values.",
50 "The reference-counted pointer type.",
51 "The source type of the structure.",
52 "The target type of the structure.",
53 "The source type of the focus.",
54 "The target type of the focus."
55 )]
56 #[document_parameters("The review instance.")]
57 impl<'a, PointerBrand, S, T, A, B> Clone for Review<'a, PointerBrand, S, T, A, B>
58 where
59 PointerBrand: UnsizedCoercible,
60 S: 'a,
61 T: 'a,
62 A: 'a,
63 B: 'a,
64 {
65 #[document_signature]
66 #[document_returns("A new `Review` instance that is a copy of the original.")]
67 #[document_examples]
68 fn clone(&self) -> Self {
80 Review {
81 review_fn: self.review_fn.clone(),
82 _phantom: PhantomData,
83 }
84 }
85 }
86
87 #[document_type_parameters(
88 "The lifetime of the values.",
89 "The reference-counted pointer type.",
90 "The source type of the structure.",
91 "The target type of the structure.",
92 "The source type of the focus.",
93 "The target type of the focus."
94 )]
95 #[document_parameters("The review instance.")]
96 impl<'a, PointerBrand, S, T, A, B> Review<'a, PointerBrand, S, T, A, B>
97 where
98 PointerBrand: UnsizedCoercible,
99 S: 'a,
100 T: 'a,
101 A: 'a,
102 B: 'a,
103 {
104 #[document_signature]
106 #[document_parameters("The review function.")]
108 #[document_returns("A new instance of the type.")]
110 #[document_examples]
112 pub fn new(review: impl 'a + Fn(B) -> T) -> Self {
123 Review {
124 review_fn: <FnBrand<PointerBrand> as LiftFn>::new(review),
125 _phantom: PhantomData,
126 }
127 }
128
129 #[document_signature]
131 #[document_parameters("The focus value to review.")]
133 #[document_returns("The structure containing the focus value.")]
135 #[document_examples]
137 pub fn review(
148 &self,
149 b: B,
150 ) -> T {
151 (self.review_fn)(b)
152 }
153 }
154
155 #[document_type_parameters(
156 "The lifetime of the values.",
157 "The reference-counted pointer type.",
158 "The source type of the structure.",
159 "The target type of the structure.",
160 "The source type of the focus.",
161 "The target type of the focus."
162 )]
163 #[document_parameters("The review instance.")]
164 impl<'a, PointerBrand, S, T, A, B> Optic<'a, TaggedBrand, S, T, A, B>
165 for Review<'a, PointerBrand, S, T, A, B>
166 where
167 PointerBrand: UnsizedCoercible,
168 S: 'a,
169 T: 'a,
170 A: 'a,
171 B: 'a,
172 {
173 #[document_signature]
174 #[document_parameters("The profunctor value to transform.")]
175 #[document_returns("The transformed profunctor value.")]
176 #[document_examples]
177 fn evaluate(
195 &self,
196 pab: Apply!(<TaggedBrand as Kind!( type Of<'b, X: 'b, Y: 'b>: 'b; )>::Of<'a, A, B>),
197 ) -> Apply!(<TaggedBrand as Kind!( type Of<'b, X: 'b, Y: 'b>: 'b; )>::Of<'a, S, T>) {
198 let review = self.review_fn.clone();
199 Tagged::new(review(pab.0))
200 }
201 }
202
203 #[document_type_parameters(
204 "The lifetime of the values.",
205 "The reference-counted pointer type.",
206 "The source type of the structure.",
207 "The target type of the structure.",
208 "The source type of the focus.",
209 "The target type of the focus."
210 )]
211 #[document_parameters("The review instance.")]
212 impl<'a, PointerBrand, S, T, A, B> ReviewOptic<'a, S, T, A, B>
213 for Review<'a, PointerBrand, S, T, A, B>
214 where
215 PointerBrand: UnsizedCoercible,
216 S: 'a,
217 T: 'a,
218 A: 'a,
219 B: 'a,
220 {
221 #[document_signature]
222 #[document_parameters("The profunctor value to transform.")]
223 #[document_returns("The transformed profunctor value.")]
224 #[document_examples]
225 fn evaluate(
243 &self,
244 pab: Apply!(<TaggedBrand as Kind!( type Of<'b, X: 'b, Y: 'b>: 'b; )>::Of<'a, A, B>),
245 ) -> Apply!(<TaggedBrand as Kind!( type Of<'b, X: 'b, Y: 'b>: 'b; )>::Of<'a, S, T>) {
246 Optic::<TaggedBrand, S, T, A, B>::evaluate(self, pab)
247 }
248 }
249
250 #[document_type_parameters(
254 "The lifetime of the values.",
255 "The reference-counted pointer type.",
256 "The type of the structure.",
257 "The type of the focus."
258 )]
259 pub struct ReviewPrime<'a, PointerBrand, S, A>
260 where
261 PointerBrand: UnsizedCoercible,
262 S: 'a,
263 A: 'a, {
264 pub review_fn: Apply!(<FnBrand<PointerBrand> as Kind!( type Of<'b, U: 'b, V: 'b>: 'b; )>::Of<'a, A, S>),
266 pub(crate) _phantom: PhantomData<PointerBrand>,
267 }
268
269 #[document_type_parameters(
270 "The lifetime of the values.",
271 "The reference-counted pointer type.",
272 "The type of the structure.",
273 "The type of the focus."
274 )]
275 #[document_parameters("The review instance.")]
276 impl<'a, PointerBrand, S, A> Clone for ReviewPrime<'a, PointerBrand, S, A>
277 where
278 PointerBrand: UnsizedCoercible,
279 S: 'a,
280 A: 'a,
281 {
282 #[document_signature]
283 #[document_returns("A new `ReviewPrime` instance that is a copy of the original.")]
284 #[document_examples]
285 fn clone(&self) -> Self {
297 ReviewPrime {
298 review_fn: self.review_fn.clone(),
299 _phantom: PhantomData,
300 }
301 }
302 }
303
304 #[document_type_parameters(
305 "The lifetime of the values.",
306 "The reference-counted pointer type.",
307 "The type of the structure.",
308 "The type of the focus."
309 )]
310 #[document_parameters("The review instance.")]
311 impl<'a, PointerBrand, S, A> ReviewPrime<'a, PointerBrand, S, A>
312 where
313 PointerBrand: UnsizedCoercible,
314 S: 'a,
315 A: 'a,
316 {
317 #[document_signature]
319 #[document_parameters("The review function.")]
321 #[document_returns("A new instance of the type.")]
323 #[document_examples]
325 pub fn new(review: impl 'a + Fn(A) -> S) -> Self {
336 ReviewPrime {
337 review_fn: <FnBrand<PointerBrand> as LiftFn>::new(review),
338 _phantom: PhantomData,
339 }
340 }
341
342 #[document_signature]
344 #[document_parameters("The focus value to review.")]
346 #[document_returns("The structure containing the focus value.")]
348 #[document_examples]
350 pub fn review(
361 &self,
362 a: A,
363 ) -> S {
364 (self.review_fn)(a)
365 }
366 }
367
368 #[document_type_parameters(
369 "The lifetime of the values.",
370 "The reference-counted pointer type.",
371 "The type of the structure.",
372 "The type of the focus."
373 )]
374 #[document_parameters("The review instance.")]
375 impl<'a, PointerBrand, S, A> Optic<'a, TaggedBrand, S, S, A, A>
376 for ReviewPrime<'a, PointerBrand, S, A>
377 where
378 PointerBrand: UnsizedCoercible,
379 S: 'a,
380 A: 'a,
381 {
382 #[document_signature]
383 #[document_parameters("The profunctor value to transform.")]
384 #[document_returns("The transformed profunctor value.")]
385 #[document_examples]
386 fn evaluate(
404 &self,
405 pab: Apply!(<TaggedBrand as Kind!( type Of<'b, X: 'b, Y: 'b>: 'b; )>::Of<'a, A, A>),
406 ) -> Apply!(<TaggedBrand as Kind!( type Of<'b, X: 'b, Y: 'b>: 'b; )>::Of<'a, S, S>) {
407 let review = self.review_fn.clone();
408 Tagged::new(review(pab.0))
409 }
410 }
411
412 #[document_type_parameters(
413 "The lifetime of the values.",
414 "The reference-counted pointer type.",
415 "The type of the structure.",
416 "The type of the focus."
417 )]
418 #[document_parameters("The review instance.")]
419 impl<'a, PointerBrand, S, A> ReviewOptic<'a, S, S, A, A> for ReviewPrime<'a, PointerBrand, S, A>
420 where
421 PointerBrand: UnsizedCoercible,
422 S: 'a,
423 A: 'a,
424 {
425 #[document_signature]
426 #[document_parameters("The profunctor value to transform.")]
427 #[document_returns("The transformed profunctor value.")]
428 #[document_examples]
429 fn evaluate(
447 &self,
448 pab: Apply!(<TaggedBrand as Kind!( type Of<'b, X: 'b, Y: 'b>: 'b; )>::Of<'a, A, A>),
449 ) -> Apply!(<TaggedBrand as Kind!( type Of<'b, X: 'b, Y: 'b>: 'b; )>::Of<'a, S, S>) {
450 Optic::<TaggedBrand, S, S, A, A>::evaluate(self, pab)
451 }
452 }
453}
454pub use inner::*;