then<C> method
Composes this isomorphism with another isomorphism.
Chains two isomorphisms: A ↔ B and B ↔ C to create a new isomorphism
A ↔ C. This allows you to build complex transformations by composing
simpler ones.
The composition follows mathematical function composition:
- Forward:
other.to(to(a))- apply this iso's to, then the other's to - Backward:
from(other.from(c))- apply the other's from, then this iso's from
Type parameter C is the final type in the chain.
Example:
// Chain: String -> int -> bool (if int.isEven)
final toInt = Iso(to: int.parse, from: (i) => i.toString());
final toBool = Iso(to: (i) => i.isEven, from: (b) => b ? 2 : 1);
final stringToBool = toInt.then(toBool);
assert(stringToBool.to('4') == true); // '4' -> 4 -> true
assert(stringToBool.from(false) == '1'); // false -> 1 -> '1'
Implementation
Iso<A, C> then<C>(Iso<B, C> other) =>
Iso(to: (a) => other.to(to(a)), from: (c) => from(other.from(c)));