Skip to content

Home

go-composites

A collection of pure-Go composites for Composition-Oriented Programming: small, interface-first building blocks — a null sentinel, an error interface, a result wrapper, boxed boolean/number/string values, an array and a dictionary, a compose pipeline, a one-import meta-package, and a typed generics track. No cgo, no third-party runtime dependencies (only go-spew in a demo main).

The design is deliberately composition-oriented: each package exposes an Interface and a private data struct constructed through a New(...) function (several use functional options such as WithPayload / WithGoString). Composites are assembled by composing and delegating to smaller composites, never by inheritance. Fallible methods return a result value rather than the Go idiom of multiple return values, so the packages compose with one another, and the Null-Object pattern runs throughout — a fresh Result, Error or Null is a real, non-nil value, so callers branch on HasError() instead of nil checks.

Module paths

Org and module path

These projects live in the GitHub organisation go-composites, and their Go module paths match it — github.com/go-composites/<name>. For example the array repository declares module github.com/go-composites/array. The importable package lives under the src/ sub-directory (e.g. github.com/go-composites/array/src, package Array).

The one exception is the composites meta-package, which is imported at the module root — import "github.com/go-composites/composites".

Components

ModuleImport pathWhat it does
basegithub.com/go-composites/base/srcThe reflective root every composite embeds: Kind()/RespondTo()/Methods() via reflection, so each repo’s surface stays small.
nullgithub.com/go-composites/null/srcA minimal null-object sentinel used as the default result payload.
errorgithub.com/go-composites/error/srcThe error interface (Message/IsNull) plus null and method-not-implemented sentinels.
resultgithub.com/go-composites/result/srcWraps a payload plus an error built with functional options; HasError() is true only on a real error.
booleangithub.com/go-composites/boolean/srcA boxed boolean (IsTrue/IsFalse/Equal); its structural IsTrue() is what array’s combinators treat as truthy.
numbergithub.com/go-composites/number/srcA boxed numeric value (int/float); arithmetic returns a result, so division by zero is an error value, not a panic.
bignumbergithub.com/go-composites/bignumber/srcAn arbitrary-precision integer over math/big.Int (no overflow); unbounded-precision complement to number, arithmetic returns a result.
rationalgithub.com/go-composites/rational/srcAn exact rational number over math/big.Rat (Ruby’s Rational); fractions stay in lowest terms, arithmetic returns a result.
complexgithub.com/go-composites/complex/srcA complex number a+bi over complex128 (Ruby’s Complex); arithmetic returns a result, with Abs/Conjugate.
bigfloatgithub.com/go-composites/bigfloat/srcAn arbitrary-precision float over math/big.Float (256-bit mantissa, Ruby’s BigDecimal); exact decimals, arithmetic returns a result.
stringgithub.com/go-composites/string/srcA boxed string value with Set/ToGoString/Split.
buffergithub.com/go-composites/buffer/srcA mutable text buffer (StringBuilder); Append/AppendRune/Reset mutate in place and chain — the mutable counterpart to string.
symbolgithub.com/go-composites/symbol/srcAn interned, immutable identifier (Ruby’s :name); New("x") == New("x").
timegithub.com/go-composites/time/srcA deterministic instant (no Now()) with embedded-tzdata IANA zone support (In/Zone/UTC) plus a Duration sub-package; fallible Parse/Add/In return a result.
dategithub.com/go-composites/date/srcA deterministic calendar date (year/month/day, no time-of-day; no Today()), the pure-calendar complement to time; fallible FromYMD/Parse/AddDays return a result.
arraygithub.com/go-composites/array/srcInterface-first slice with Push/Pop/First/Fetch/Each plus combinators Map/Filter/Reduce/Find/Any/All; every method returns a result.
dictionarygithub.com/go-composites/dictionary/srcAn interface-first key/value map; Get of a missing key returns a result error, not a panic.
setgithub.com/go-composites/set/srcAn unordered collection of unique items with Union/Intersection/Difference.
orderedsetgithub.com/go-composites/orderedset/srcThe insertion-ordered sibling of set: same API, but iteration is in first-insertion order.
sortedsetgithub.com/go-composites/sortedset/srcThe comparator-sorted sibling of set: items kept in ascending less-comparator order (TreeSet-like).
baggithub.com/go-composites/bag/srcA counted collection (multiset): items carry a multiplicity, with Count/Len/DistinctLen and multiset Sum/Union/Intersection/Difference.
rangegithub.com/go-composites/range/srcAn integer interval (inclusive/exclusive end, non-zero step); a zero step is a result error, not a panic.
pairgithub.com/go-composites/pair/srcA fixed two-element heterogeneous grouping (First/Second/ToArray).
procgithub.com/go-composites/proc/srcA first-class callable; Then chains steps railway-style, short-circuiting on an error result.
enumeratorgithub.com/go-composites/enumerator/srcA lazy sequence (Ruby Enumerator::Lazy): lazy Map/Filter/Take over a finite or infinite source; result-based terminals.
composegithub.com/go-composites/compose/srcPipe/Run compose result-returning steps into one left-to-right, short-circuiting pipeline.
compositesgithub.com/go-composites/compositesMeta-package: one import re-exporting the whole vocabulary as type aliases + constructors.
typedgithub.com/go-composites/typed/src/...A generics parallel track: Result[T], Optional[T], Slice[T] with compile-time type safety.

Analyzers

ToolWhat it enforces
nonnilA go vet-style analyzer that fails the build when an interface carrying IsNull() is returned, assigned, or stored as a bare nil — the Null-Object invariant.
respondtoA go vet-style analyzer that flags RespondTo reflective sends to a method that does not exist.

Dependency shape

compose ─┐
string ──┼▶ array ──▶ result ──▶ error
number ──┤              └─────▶ null
boolean ─┘
dictionary ─▶ result

error and null are leaf packages with no intra-org dependencies; result composes them; the value and collection composites build on result. The composites meta-package imports them all and re-exports them; typed is standalone with zero dependencies.

Quality bar

Every library (src) package is held to 100% statement coverage (an org hard rule, gated in CI) and is built and tested across a native + emulated six-architecture matrix (amd64, arm64, riscv64, loong64, ppc64le, s390x). Two static analyzers enforce the org’s invariants on every repo: nonnil for the Null-Object rule and respondto for reflective dispatch. Everything is pure Go (CGO_ENABLED=0) and BSD-3-Clause.