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
/*
* SPDX-License-Identifier: MIT
* Copyright (c) 2023 - 2026. The DeepCausality Authors and Contributors. All Rights Reserved.
*/
use crateHKT2Unbound;
/// The `Bifunctor` trait allows mapping over both arguments of a type constructor `F<A, B>`.
///
/// # Category Theory
/// A **Bifunctor** is a functor from the product category $\mathcal{C} \times \mathcal{D}$ to $\mathcal{E}$.
/// It satisfies the functor laws for both arguments independently and simultaneously.
///
/// * **Bimap**: $(A \to C) \to (B \to D) \to F(A, B) \to F(C, D)$
///
/// # Mathematical Definition
/// Let $B: \mathcal{C} \times \mathcal{D} \to \mathcal{E}$ be a bifunctor.
/// For any two morphisms $f: A \to C$ and $g: B \to D$, there exists a morphism
/// $B(f, g): B(A, B) \to B(C, D)$ such that:
/// 1. $B(id_A, id_B) = id_{B(A, B)}$
/// 2. $B(f' \circ f, g' \circ g) = B(f', g') \circ B(f, g)$
///
/// Laws are stated for pure functions; a stateful `FnMut` closure voids them.
/// Machine-checked in `lean/DeepCausalityFormal/Haft/Bifunctor.lean`.
///
/// # Use Cases
/// * **Result Handling**: Mapping both `Ok` and `Err` variants of a `Result<T, E>`.
/// * **Systems Evolution**: Evolving a `System<Topology, Algebra>` where both components change type.