Skip to content

Add construct (polymorphic function builder) to Made.Product #54

@halotukozak

Description

@halotukozak

Follow-up to #51 (typed-builder).

Made.Product.fromTuple covers the typed builder use case. Magnolia-style construct
may also be valuable for derivation typeclass scenarios where a per-field function
materializes values.

Proposal (shape TBD)

One possible signature — exact shape not decided:

def construct(f: [e <: MadeFieldElem] => (elem: e) => elem.Type): Type

Alternatives worth considering:

  • Magnolia-style homogeneous [R](f: MadeFieldElem => R): T with cast
  • Rank-2 trait trait Constructor[T] { def apply[X](elem: MadeFieldElem { type Type = X }): X }
  • Typeclass-aware variant requiring F[t] summon per field

Implementation notes (if polymorphic-function shape)

  • Polymorphic function application inside macro quotes
  • Macro-time unrolling of Elems tuple to preserve per-field path-dependent typing at each f($e) call site
  • Builds on fromTuple — generated body roughly m.fromProduct((f(e0), f(e1), ...))

Why deferred

Requires polymorphic function application inside quotes plus macro-side tuple unrolling — more
involved than fromTuple. Deferred to keep #51 minimal. Non-breaking to add later.

Concrete consumer use cases would help nail down the exact API shape.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions