Skip to content

feat(fanout): variadic composition + fanout(keypaths:into:) - #100

Merged
luizmb merged 1 commit into
mainfrom
feature/variadic-fanout
Jul 22, 2026
Merged

feat(fanout): variadic composition + fanout(keypaths:into:)#100
luizmb merged 1 commit into
mainfrom
feature/variadic-fanout

Conversation

@luizmb

@luizmb luizmb commented Jul 22, 2026

Copy link
Copy Markdown
Owner

What

Two point-free ways to fan a value out over several accessors and feed the pieces straight into a multi-argument function (typically a memberwise init): a variadic >>>/<<< overload, and fanout(keypaths:into:).

Why

Narrowing a large value into a smaller one whose init takes the parts as separate arguments — e.g. deriving a feature's Environment from a big World — is a constant shape. Plain fanout(…) >>> Env.init can't type-check because Swift (SE-0110) treats a tuple argument and a multi-argument parameter list as distinct types. A variadic overload of >>> bridges the two; for callers who'd rather avoid the operator, fanout(keypaths:into:) closes the loop in one call.

struct Env: Sendable { init(badge: Int, save: Int) {  } }

let a: @Sendable (World) -> Env = fanout(\.badge, \.save) >>> Env.init
let b: @Sendable (World) -> Env = fanout(keypaths: \.badge, \.save, into: Env.init)

The variadic >>> coexists with the single-argument overload without ambiguity (single-output → plain overload, tuple-output → variadic).

Changes

  • CoreFPOperators/Function/FunctionComposition.swift — add variadic >>>/<<< overloads composing (Root) -> (repeat each T) with (repeat each T) -> Out.
  • CoreFP/Utilities/Fanout.swift — add fanout(keypaths:into:) (key paths constrained to Sendable); make the existing fanout(_:) return @Sendable.
  • Tests — FanoutTests (new) + variadic composition cases in FunctionCompositionTests.
  • Docs — README fan-out subsection; DocC PointFreeStyle + CoreFPOperators articles.

Full suite green (2775 tests); swiftlint --strict clean on changed files.

🤖 Generated with Claude Code

…rg composition

Bridge the SE-0110 gap between a fanout's tuple and a multi-argument
initializer, so narrowing a large value into a smaller one whose init
takes the parts as separate arguments is point-free:

    fanout(\.badge, \.save) >>> Env.init              // operator
    fanout(keypaths: \.badge, \.save, into: Env.init) // symbol-free

- Add variadic `>>>`/`<<<` overloads composing `(Root) -> (repeat each T)`
  with `(repeat each T) -> Out`; coexist with the single-arg overloads
  without ambiguity.
- Add `fanout(keypaths:into:)` — key paths (constrained to Sendable) fanned
  straight into a multi-arg function, no intermediate tuple spelled out.
- Make the existing `fanout(_:)` return `@Sendable`.
- Tests (FanoutTests + variadic composition cases) and docs (README, DocC).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01E7QbufqFGENZXn4RwDPS6x
@luizmb
luizmb merged commit 2404400 into main Jul 22, 2026
5 checks passed
@luizmb
luizmb deleted the feature/variadic-fanout branch July 22, 2026 16:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant