@hackage alignment0.2.0.0

Principled functor alignment with leftovers

A principled approach to zipping functors that preserves both matched pairs and leftovers.

The alignment library provides type classes and operations for aligning two functors into a structure (This) that captures:

  • Matched pairs where both functors have elements at the same position

  • Leftovers when one functor is longer than the other

This is more principled than traditional zip which silently discards extra elements. The library uses functional dependencies (f -> g) to relate the "paired" functor to the "leftover" functor, ensuring type safety.

Key features:

  • Semialign, Align, and Unalign type classes with comprehensive laws

  • Unalign provides inverse operation to recover original functors

  • Full lens/optics integration

  • Instances for common functors: [], Maybe, NonEmpty, Vector, Map, Seq, and more

  • Testable law-checking functions for property-based testing

  • Complete documentation with 211 doctests

Example:

import Data.Alignment

-- Align two lists of different lengths
align [1,2,3] [10,20] :: This [] NonEmpty Int Int
-- Result: This [(1,10),(2,20)] (Just (Left (3 :| [])))