ordofp_core 0.1.0

OrdoFP core provides developers with HList, Disiunctio, NominataUniversalis, Universalis, and functional type classes
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
//! Optics for `OrdoFP`
//!
//! > *\"Aspectus est actus intellectus quo rem intuetur.\"*
//! > — An aspect is the act of the intellect by which it beholds a thing. (Scholastic)
//!
//! Composable accessors for nested immutable data: lenses, prisms, isos,
//! traversals, and profunctor-style optics.
//!
//! # `OrdoFP` 3.0 Optics Enhancement (Optica Nova)
//!
//! This module now includes advanced optics features:
//!
//! - **Profunctor Optics** - Van Laarhoven style optics for principled composition
//! - **Affine Traversals** - Optics that focus on 0 or 1 elements
//! - **At Optics** - Indexed container access with `Ad` trait
//!
//! # Scholastic Names
//!
//! | English | Latin | Etymology |
//! |---------|-------|-----------|
//! | Lens | Aspectus | *aspectus* = sight, appearance |
//! | Prism | Divisio | *divisio* = division |
//! | Iso | Aequivalentia | *aequivalentia* = equivalence |
//! | Traversal | Iteratio | *iteratio* = repetition |
//! | Affine | Affinis | *affinis* = neighboring, related |
//! | At | Ad | *ad* = at, to |
//! | Profunctor | Profunctor | *pro* + *functor* |
//! | Strong | Fortis | *fortis* = strong |
//! | Choice | Electio | *electio* = choice |
//!
//! # Overview
//!
//! Optics provide a unified interface for:
//! - **Aspectus** (Lens): Focus on a single field within a product type (struct)
//! - **Divisio** (Prism): Focus on a single variant within a sum type (enum)
//! - **Aequivalentia** (Iso): Bidirectional lossless transformation between two types
//! - **`IteratioAffinis`** (Affine): Focus on 0 or 1 elements (optional access)
//! - **Ad** (At): Indexed container access
//!
//! # Aspectus (Lens) Example
//!
//! ```rust
//! use ordofp_core::optics::{Aspectus, aspectus};
//!
//! #[derive(Clone, Debug, PartialEq)]
//! struct Person {
//!     name: String,
//!     age: u32,
//! }
//!
//! // Create an aspectus focusing on the `name` field
//! let name_aspectus = aspectus(
//!     |p: &Person| p.name.clone(),
//!     |p: &Person, name: String| Person { name, age: p.age },
//! );
//!
//! let person = Person { name: "Alice".to_string(), age: 30 };
//!
//! // Get the name
//! assert_eq!(name_aspectus.get(&person), "Alice");
//!
//! // Set a new name (returns a new Person)
//! let updated = name_aspectus.set(&person, "Bob".to_string());
//! assert_eq!(updated.name, "Bob");
//!
//! // Modify the name using a function
//! let uppercased = name_aspectus.modify(&person, |s| s.to_uppercase());
//! assert_eq!(uppercased.name, "ALICE");
//! ```
//!
//! # Divisio (Prism) Example
//!
//! ```rust
//! use ordofp_core::optics::{Divisio, divisio};
//!
//! #[derive(Clone, Debug, PartialEq)]
//! enum Shape {
//!     Circle(f64),
//!     Rectangle(f64, f64),
//! }
//!
//! // Create a divisio focusing on the Circle variant
//! let circle_divisio = divisio(
//!     |s: &Shape| match s {
//!         Shape::Circle(r) => Some(*r),
//!         _ => None,
//!     },
//!     |r: f64| Shape::Circle(r),
//! );
//!
//! let circle = Shape::Circle(5.0);
//! let rect = Shape::Rectangle(3.0, 4.0);
//!
//! // Preview (get if the variant matches)
//! assert_eq!(circle_divisio.preview(&circle), Some(5.0));
//! assert_eq!(circle_divisio.preview(&rect), None);
//!
//! // Review (construct the variant)
//! assert_eq!(circle_divisio.review(10.0), Shape::Circle(10.0));
//! ```
//!
//! # Aequivalentia (Iso) Example
//!
//! ```rust
//! use ordofp_core::optics::{Aequivalentia, aequivalentia};
//!
//! // Isomorphism between (A, B) and (B, A)
//! let swap_aeq = aequivalentia(
//!     |pair: &(i32, String)| (pair.1.clone(), pair.0),
//!     |pair: &(String, i32)| (pair.1, pair.0.clone()),
//! );
//!
//! let pair = (42, "hello".to_string());
//! let swapped = swap_aeq.forward(&pair);
//! assert_eq!(swapped, ("hello".to_string(), 42));
//!
//! let back = swap_aeq.backward(&swapped);
//! assert_eq!(back, pair);
//! ```
//!
//! # Composition
//!
//! Optics can be composed to access deeply nested data:
//!
//! ```rust
//! use ordofp_core::optics::{Aspectus, aspectus};
//!
//! #[derive(Clone, Debug, PartialEq)]
//! struct Address {
//!     street: String,
//!     city: String,
//! }
//!
//! #[derive(Clone, Debug, PartialEq)]
//! struct Person {
//!     name: String,
//!     address: Address,
//! }
//!
//! let address_aspectus = aspectus(
//!     |p: &Person| p.address.clone(),
//!     |p: &Person, addr: Address| Person { name: p.name.clone(), address: addr },
//! );
//!
//! let street_aspectus = aspectus(
//!     |a: &Address| a.street.clone(),
//!     |a: &Address, street: String| Address { street, city: a.city.clone() },
//! );
//!
//! // Compose aspectus to focus on person.address.street
//! let person_street = address_aspectus.compose(&street_aspectus);
//!
//! let person = Person {
//!     name: "Alice".to_string(),
//!     address: Address {
//!         street: "123 Main St".to_string(),
//!         city: "Springfield".to_string(),
//!     },
//! };
//!
//! assert_eq!(person_street.get(&person), "123 Main St");
//!
//! let updated = person_street.set(&person, "456 Oak Ave".to_string());
//! assert_eq!(updated.address.street, "456 Oak Ave");
//! ```
//!
//! # Performance: read-only access on hot paths
//!
//! [`Aspectus::get`] returns the focus **by value**, so the getter must clone it;
//! worse, [`ComposedAspectus::get`] clones the *entire intermediate* structure on
//! every read (measured ~144 ns / ~7 allocations for a `String` field two levels
//! deep). When you only need to **read** (not `set`/`modify`), use the borrowing
//! [`AspectusRef`] and [`AspectusRef::compose`] instead: reads return a `&` and
//! compose with **zero clones**, matching hand-written field access (~0.27 ns,
//! ~520× faster). Reach for `Aspectus` only when you need the owning `set`/`modify`.
//!
//! ```rust
//! use ordofp_core::optics::AspectusRef;
//!
//! struct Address { street: String }
//! struct Person { address: Address }
//!
//! let address = AspectusRef::new(|p: &Person| &p.address);
//! let street = AspectusRef::new(|a: &Address| &a.street);
//! let person_street = address.compose(&street);
//!
//! let p = Person { address: Address { street: "123 Main St".to_string() } };
//! assert_eq!(person_street.get(&p), "123 Main St"); // no clone
//! ```
//!
//! # Aspectus Laws
//!
//! A well-behaved aspectus must satisfy three laws:
//!
//! 1. **`GetSet`**: `aspectus.set(s, aspectus.get(s)) == s`
//!    Setting what you got doesn't change anything.
//!
//! 2. **`SetGet`**: `aspectus.get(aspectus.set(s, a)) == a`
//!    Getting what you set returns what you set.
//!
//! 3. **`SetSet`**: `aspectus.set(aspectus.set(s, a), b) == aspectus.set(s, b)`
//!    Setting twice is the same as setting once with the final value.
//!
//! # Divisio Laws
//!
//! A well-behaved divisio must satisfy two laws:
//!
//! 1. **`PreviewReview`**: `divisio.preview(divisio.review(a)) == Some(a)`
//!    Previewing a reviewed value returns that value.
//!
//! 2. **`ReviewPreview`**: If `divisio.preview(s) == Some(a)`, then `divisio.review(a) == s`
//!    Reviewing a previewed value reconstructs the original (when the preview succeeds).

pub mod affine;
pub mod at;
mod iso;
mod lens;
mod prism;
pub mod profunctor;
/// Iteratio (traversal) optics: focus on zero-or-more elements of a
/// structure at once, for bulk get/modify.
pub mod traversal;

// Primary exports (scholastic names)
pub use iso::{
    Aequivalentia, AequivalentiaRef, ComposedAequivalentia, PermutatioAequivalentia, aequivalentia,
    identitas, permutatio,
};
pub use lens::{Aspectus, AspectusRef, ComposedAspectus, ComposedAspectusRef, aspectus};
pub use prism::{ComposedDivisio, Divisio, DivisioRef, divisio};
pub use traversal::Iteratio;

// Profunctor optics exports
pub use profunctor::{
    AequivalentiaProfunctor, AequivalentiaSimplexProf, AspectusProfunctor, AspectusSimplexProf,
    ComposedOptic, DivisioProfunctor, DivisioSimplexProf, Electio, Fortis, FunctioProf,
    OpticumProfunctor, Profunctor, aequivalentia_profunctor, aspectus_profunctor,
    aspectus_profunctor_poly, divisio_profunctor, divisio_profunctor_poly,
};

// Affine traversal exports
pub use affine::{
    ComposedIteratioAffinis, IteratioAffinis, IteratioAffinisPolymorphica, iteratio_affinis,
    iteratio_option,
};
#[cfg(feature = "alloc")]
pub use affine::{iteratio_at_index, iteratio_at_key};

// At (indexed access) exports
pub use at::{Ad, AdExt, AdInserere, AdRemovere, AspectusAd, Ix, aspectus_ad};

#[cfg(test)]
mod tests {
    use super::*;

    extern crate alloc;
    use alloc::string::{String, ToString};

    // Test structures
    #[derive(Clone, Debug, PartialEq)]
    struct Person {
        name: String,
        age: u32,
    }

    #[derive(Clone, Debug, PartialEq)]
    struct Address {
        street: String,
        city: String,
    }

    #[derive(Clone, Debug, PartialEq)]
    struct PersonWithAddress {
        person: Person,
        address: Address,
    }

    #[derive(Clone, Debug, PartialEq)]
    enum Shape {
        Circle(f64),
        Rectangle(f64, f64),
    }

    #[derive(Clone, Debug, PartialEq)]
    enum Result2<T, E> {
        Ok(T),
        Err(E),
    }

    // ==================== Lens Tests ====================

    #[test]
    fn test_lens_get() {
        let name_lens = aspectus(
            |p: &Person| p.name.clone(),
            |p: &Person, name: String| Person { name, age: p.age },
        );

        let person = Person {
            name: "Alice".to_string(),
            age: 30,
        };

        assert_eq!(name_lens.get(&person), "Alice");
    }

    #[test]
    fn test_lens_set() {
        let name_lens = aspectus(
            |p: &Person| p.name.clone(),
            |p: &Person, name: String| Person { name, age: p.age },
        );

        let person = Person {
            name: "Alice".to_string(),
            age: 30,
        };

        let updated = name_lens.set(&person, "Bob".to_string());
        assert_eq!(updated.name, "Bob");
        assert_eq!(updated.age, 30);
    }

    #[test]
    fn test_lens_modify() {
        let name_lens = aspectus(
            |p: &Person| p.name.clone(),
            |p: &Person, name: String| Person { name, age: p.age },
        );

        let person = Person {
            name: "Alice".to_string(),
            age: 30,
        };

        let modified = name_lens.modify(&person, |s| s.to_uppercase());
        assert_eq!(modified.name, "ALICE");
    }

    #[test]
    fn test_lens_composition() {
        let address_lens = aspectus(
            |p: &PersonWithAddress| p.address.clone(),
            |p: &PersonWithAddress, addr: Address| PersonWithAddress {
                person: p.person.clone(),
                address: addr,
            },
        );

        let street_lens = aspectus(
            |a: &Address| a.street.clone(),
            |a: &Address, street: String| Address {
                street,
                city: a.city.clone(),
            },
        );

        let composed = address_lens.compose(&street_lens);

        let person_with_addr = PersonWithAddress {
            person: Person {
                name: "Alice".to_string(),
                age: 30,
            },
            address: Address {
                street: "123 Main St".to_string(),
                city: "Springfield".to_string(),
            },
        };

        assert_eq!(composed.get(&person_with_addr), "123 Main St");

        let updated = composed.set(&person_with_addr, "456 Oak Ave".to_string());
        assert_eq!(updated.address.street, "456 Oak Ave");
    }

    #[test]
    fn test_lens_law_get_set() {
        // GetSet: aspectus.set(s, aspectus.get(s)) == s
        let name_lens = aspectus(
            |p: &Person| p.name.clone(),
            |p: &Person, name: String| Person { name, age: p.age },
        );

        let person = Person {
            name: "Alice".to_string(),
            age: 30,
        };

        let result = name_lens.set(&person, name_lens.get(&person));
        assert_eq!(result, person);
    }

    #[test]
    fn test_lens_law_set_get() {
        // SetGet: aspectus.get(aspectus.set(s, a)) == a
        let name_lens = aspectus(
            |p: &Person| p.name.clone(),
            |p: &Person, name: String| Person { name, age: p.age },
        );

        let person = Person {
            name: "Alice".to_string(),
            age: 30,
        };

        let new_name = "Bob".to_string();
        let result = name_lens.get(&name_lens.set(&person, new_name.clone()));
        assert_eq!(result, new_name);
    }

    #[test]
    fn test_lens_law_set_set() {
        // SetSet: aspectus.set(aspectus.set(s, a), b) == aspectus.set(s, b)
        let name_lens = aspectus(
            |p: &Person| p.name.clone(),
            |p: &Person, name: String| Person { name, age: p.age },
        );

        let person = Person {
            name: "Alice".to_string(),
            age: 30,
        };

        let a = "Bob".to_string();
        let b = "Charlie".to_string();

        let result1 = name_lens.set(&name_lens.set(&person, a), b.clone());
        let result2 = name_lens.set(&person, b);
        assert_eq!(result1, result2);
    }

    // ==================== Prism Tests ====================

    #[test]
    fn test_prism_preview_some() {
        let circle_prism = divisio(
            |s: &Shape| match s {
                Shape::Circle(r) => Some(*r),
                _ => None,
            },
            Shape::Circle,
        );

        let circle = Shape::Circle(5.0);
        assert_eq!(circle_prism.preview(&circle), Some(5.0));
    }

    #[test]
    fn test_prism_preview_none() {
        let circle_prism = divisio(
            |s: &Shape| match s {
                Shape::Circle(r) => Some(*r),
                _ => None,
            },
            Shape::Circle,
        );

        let rect = Shape::Rectangle(3.0, 4.0);
        assert_eq!(circle_prism.preview(&rect), None);
    }

    #[test]
    fn test_prism_review() {
        let circle_prism = divisio(
            |s: &Shape| match s {
                Shape::Circle(r) => Some(*r),
                _ => None,
            },
            Shape::Circle,
        );

        assert_eq!(circle_prism.review(10.0), Shape::Circle(10.0));
    }

    #[test]
    fn test_prism_modify_some() {
        let circle_prism = divisio(
            |s: &Shape| match s {
                Shape::Circle(r) => Some(*r),
                _ => None,
            },
            Shape::Circle,
        );

        let circle = Shape::Circle(5.0);
        let doubled = circle_prism.modify(&circle, |r| r * 2.0);
        assert_eq!(doubled, Some(Shape::Circle(10.0)));
    }

    #[test]
    fn test_prism_modify_none() {
        let circle_prism = divisio(
            |s: &Shape| match s {
                Shape::Circle(r) => Some(*r),
                _ => None,
            },
            Shape::Circle,
        );

        let rect = Shape::Rectangle(3.0, 4.0);
        let result = circle_prism.modify(&rect, |r| r * 2.0);
        assert_eq!(result, None);
    }

    #[test]
    fn test_prism_composition() {
        // Divisio for Result2::Ok
        let ok_prism = divisio(
            |r: &Result2<Shape, String>| match r {
                Result2::Ok(s) => Some(s.clone()),
                _ => None,
            },
            Result2::Ok,
        );

        // Divisio for Shape::Circle
        let circle_prism = divisio(
            |s: &Shape| match s {
                Shape::Circle(r) => Some(*r),
                _ => None,
            },
            Shape::Circle,
        );

        let composed = ok_prism.compose(&circle_prism);

        let ok_circle: Result2<Shape, String> = Result2::Ok(Shape::Circle(5.0));
        let ok_rect: Result2<Shape, String> = Result2::Ok(Shape::Rectangle(3.0, 4.0));
        let err: Result2<Shape, String> = Result2::Err("error".to_string());

        assert_eq!(composed.preview(&ok_circle), Some(5.0));
        assert_eq!(composed.preview(&ok_rect), None);
        assert_eq!(composed.preview(&err), None);
    }

    #[test]
    fn test_prism_law_preview_review() {
        // PreviewReview: divisio.preview(divisio.review(a)) == Some(a)
        let circle_prism = divisio(
            |s: &Shape| match s {
                Shape::Circle(r) => Some(*r),
                _ => None,
            },
            Shape::Circle,
        );

        let radius = 5.0;
        let result = circle_prism.preview(&circle_prism.review(radius));
        assert_eq!(result, Some(radius));
    }

    // ==================== Iso Tests ====================

    #[test]
    fn test_iso_forward() {
        let swap_iso = aequivalentia(
            |(a, b): &(i32, String)| (b.clone(), *a),
            |(b, a): &(String, i32)| (*a, b.clone()),
        );

        let pair = (42, "hello".to_string());
        let swapped = swap_iso.forward(&pair);
        assert_eq!(swapped, ("hello".to_string(), 42));
    }

    #[test]
    fn test_iso_backward() {
        let swap_iso = aequivalentia(
            |(a, b): &(i32, String)| (b.clone(), *a),
            |(b, a): &(String, i32)| (*a, b.clone()),
        );

        let pair = ("hello".to_string(), 42);
        let back = swap_iso.backward(&pair);
        assert_eq!(back, (42, "hello".to_string()));
    }

    #[test]
    fn test_iso_roundtrip_forward_backward() {
        let swap_iso = aequivalentia(
            |(a, b): &(i32, String)| (b.clone(), *a),
            |(b, a): &(String, i32)| (*a, b.clone()),
        );

        let original = (42, "hello".to_string());
        let roundtrip = swap_iso.backward(&swap_iso.forward(&original));
        assert_eq!(roundtrip, original);
    }

    #[test]
    fn test_iso_roundtrip_backward_forward() {
        let swap_iso = aequivalentia(
            |(a, b): &(i32, String)| (b.clone(), *a),
            |(b, a): &(String, i32)| (*a, b.clone()),
        );

        let original = ("hello".to_string(), 42);
        let roundtrip = swap_iso.forward(&swap_iso.backward(&original));
        assert_eq!(roundtrip, original);
    }

    #[test]
    fn test_iso_composition() {
        // Aequivalentia from (A, B) to (B, A)
        let swap1 = aequivalentia(
            |(a, b): &(i32, String)| (b.clone(), *a),
            |(b, a): &(String, i32)| (*a, b.clone()),
        );

        // Aequivalentia from (B, A) to ((B, A), ())
        let wrap = aequivalentia(
            |pair: &(String, i32)| (pair.clone(), ()),
            |(pair, ()): &((String, i32), ())| pair.clone(),
        );

        let composed = swap1.compose(&wrap);

        let original = (42, "hello".to_string());
        let result = composed.forward(&original);
        assert_eq!(result, (("hello".to_string(), 42), ()));
    }

    #[test]
    fn test_iso_reverse() {
        let swap_iso = aequivalentia(
            |(a, b): &(i32, String)| (b.clone(), *a),
            |(b, a): &(String, i32)| (*a, b.clone()),
        );

        let reversed = swap_iso.reverse();

        let pair = ("hello".to_string(), 42);
        let result = reversed.forward(&pair);
        assert_eq!(result, (42, "hello".to_string()));
    }

    // ==================== Integration Tests ====================

    #[test]
    fn test_lens_to_iso() {
        // When an aspectus is bijective, it can be viewed as an aequivalentia
        // For example, a newtype wrapper
        #[derive(Clone, Debug, PartialEq)]
        struct Age(u32);

        let age_iso = aequivalentia(|a: &Age| a.0, |n: &u32| Age(*n));

        let age = Age(30);
        assert_eq!(age_iso.forward(&age), 30);
        assert_eq!(age_iso.backward(&30), Age(30));
    }

    #[test]
    fn test_complex_nested_structure() {
        #[derive(Clone, Debug, PartialEq)]
        struct Config {
            settings: Settings,
        }

        #[derive(Clone, Debug, PartialEq)]
        struct Settings {
            theme: Theme,
        }

        #[derive(Clone, Debug, PartialEq)]
        enum Theme {
            #[allow(dead_code)] // fixture variant; only Dark/Custom are exercised
            Light,
            Dark,
            Custom(String),
        }

        // Aspectus to settings
        let settings_lens = aspectus(
            |c: &Config| c.settings.clone(),
            |_c: &Config, s: Settings| Config { settings: s },
        );

        // Aspectus to theme
        let theme_lens = aspectus(
            |s: &Settings| s.theme.clone(),
            |_s: &Settings, t: Theme| Settings { theme: t },
        );

        // Compose to get config.settings.theme
        let config_theme = settings_lens.compose(&theme_lens);

        // Divisio for Custom theme
        let custom_prism = divisio(
            |t: &Theme| match t {
                Theme::Custom(s) => Some(s.clone()),
                _ => None,
            },
            Theme::Custom,
        );

        let config = Config {
            settings: Settings {
                theme: Theme::Custom("Ocean".to_string()),
            },
        };

        // Get the theme
        let theme = config_theme.get(&config);
        assert_eq!(theme, Theme::Custom("Ocean".to_string()));

        // Check if it's a custom theme
        let custom = custom_prism.preview(&theme);
        assert_eq!(custom, Some("Ocean".to_string()));

        // Update to a new theme
        let new_config = config_theme.set(&config, Theme::Dark);
        assert_eq!(new_config.settings.theme, Theme::Dark);
    }
}