Skip to content

Implement combinators module (tuple combinators microlib) #949

@987Nabil

Description

@987Nabil

Overview

Add a new combinators module providing foundational typeclasses for tuple and sum type operations. These are zero-dependency building blocks used by the schema module and other parts of ZIO Blocks.

Typeclasses

Combiner[L, R]

Bidirectional tuple flattening with combine() and separate().

val c = Combiner[Int, String]
val combined = c.combine(42, "hello")  // (42, "hello")
val (num, str) = c.separate(combined)  // recovers original parts

Zippable[A, B]

One-way tuple flattening with zip() and discard flags. Supports ZIO-style *>, <*, <*> operators.

val z = Zippable[Int, String]
z.zip(42, "hello")  // (42, "hello")

EitherAlternator[L, R]

Either-based alternation for sum types. Works cross-version (Scala 2 + 3).

val alt = EitherAlternator[Int, String]
alt.left(42)    // Left(42)
alt.right("x")  // Right("x")

UnionAlternator[L, R] (Scala 3 only)

Union type alternation (L | R). Rejects same-type combinations since A | A = A.

val alt = UnionAlternator[Int, String]
alt.left(42)    // 42: Int | String
alt.right("x")  // "x": Int | String

StructuralCombiner[A, B] (JVM only, Scala 3 only)

Macro-based structural type merging for combining record-like types.

Module Structure

combinators/
├── jvm/src/main/scala-3/         # StructuralCombiner (JVM-only macro)
├── shared/src/main/scala-2/      # Scala 2 implementations
├── shared/src/main/scala-3/      # Scala 3 implementations  
└── shared/src/test/              # Cross-version tests

Acceptance Criteria

  • All typeclasses implemented for Scala 2.13 and Scala 3
  • Full test coverage
  • Cross-platform support (JVM/JS/Native where applicable)
  • Zero external dependencies

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions