Base interface for sum-type containers (Either, Try, etc.) that are NOT iterables.
Unlike FunctypeBase, this base deliberately excludes Traversable — which bundles
reduce / reduceRight / size / isEmpty. Those methods force A-invariance on their
containers (signature (f: (A, A) => A) => A puts A in both contravariant and covariant
positions) and have no semantic meaning for disjoint-union types where the "success"
branch is 0-or-1, not a collection.
Sum types that extend FunctypeSum can be declared covariant in their type parameter
(interface Foo<out A>) without structural check failures. This mirrors Scala's model:
Either[+L, +R] and Try[+T] do not extend Iterable; only Option[+A] extends the
lighter IterableOnce[+A].
Only the covariance-safe subset of ContainerOps is included inline: contains,
exists, and forEach all place A only in contravariant (callback input) position.
find (returns Option<A>) and count are intentionally omitted — if a sum type
needs them it can declare them directly.
Base interface for sum-type containers (Either, Try, etc.) that are NOT iterables.
Unlike
FunctypeBase, this base deliberately excludesTraversable— which bundlesreduce/reduceRight/size/isEmpty. Those methods force A-invariance on their containers (signature(f: (A, A) => A) => Aputs A in both contravariant and covariant positions) and have no semantic meaning for disjoint-union types where the "success" branch is 0-or-1, not a collection.Sum types that extend
FunctypeSumcan be declared covariant in their type parameter (interface Foo<out A>) without structural check failures. This mirrors Scala's model:Either[+L, +R]andTry[+T]do not extendIterable; onlyOption[+A]extends the lighterIterableOnce[+A].Only the covariance-safe subset of
ContainerOpsis included inline:contains,exists, andforEachall place A only in contravariant (callback input) position.find(returnsOption<A>) andcountare intentionally omitted — if a sum type needs them it can declare them directly.