dev.constructive.eo.chimney

Members list

Type members

Classlikes

object Chimney

Constructors that turn chimney's derived transformations into eo optics. Each one summons (or, for chimney's Iso / Codec, derives) the chimney value and hands it to the matching .toX extension in the chimney package — use those directly when you already hold a hand-configured chimney value (Transformer.define[…].withFieldRenamed(…).buildTransformer).

Constructors that turn chimney's derived transformations into eo optics. Each one summons (or, for chimney's Iso / Codec, derives) the chimney value and hands it to the matching .toX extension in the chimney package — use those directly when you already hold a hand-configured chimney value (Transformer.define[…].withFieldRenamed(…).buildTransformer).

Constructors, not givens: several lawful optics can share an (S, A) pair, so the caller declares the one it wants (the cats-eo doctrine for every bridge).

chimney eo optic writes?
Transformer[S, T] Getter[S, T] no
Iso[A, B] Iso[A, B] (BijectionIso) yes
Codec[Domain, Dto] Prism from Dto to Domain yes
PartialTransformer[S, T] ForgetFold[S, PartialResult, T] (keeps the errors) no
Patcher[A, P] Modify[A, A, Unit, P] (replace(p)) yes

Attributes

Source
Chimney.scala
Supertypes
class Object
trait Matchable
class Any
Self type
Chimney.type
object PartialResult

Attributes

Source
PartialResult.scala
Supertypes
class Object
trait Matchable
class Any
Self type

Types

opaque type PartialResult[A]

chimney's partial.Result[A] as the container of a optics.ForgetFold: what Chimney.resultFold and .toResultFold() read into.

chimney's partial.Result[A] as the container of a optics.ForgetFold: what Chimney.resultFold and .toResultFold() read into.

An opaque alias, not a new type — the runtime value is chimney's own partial.Result — so its companion can carry the cats instances a fold needs and core's ReadCompose finds them in implicit scope with no import (the public cats instances for partial.Result belong to chimney-cats; these are scoped to this alias). With them, a ForgetFold[S, PartialResult, A] keeps chimney's errors through composition:

  • andThen a lens / iso / Getter maps the result (Functor);
  • andThen a prism / optional / AffineFold maps it too, an inner miss becoming chimney's "empty value" error (FunctorFilter.mapFilter, via partial.Result.fromEmpty);
  • andThen another ForgetFold[A, PartialResult, C] flat-maps, so both sides' errors surface (Monad).

Multi-focus inners (Traversal, Fold over a collection) have no single result to keep and fall back to core's List fold.

Attributes

Source
PartialResult.scala

Extensions

Extensions

extension [Domain, Dto](c: Codec[Domain, Dto])
def toPrism: PickMendPrism[Dto, Domain, Domain]

This codec as a prism from Dto to Domain: getOption decodes, reverseGet encodes. See Chimney.prism.

This codec as a prism from Dto to Domain: getOption decodes, reverseGet encodes. See Chimney.prism.

Attributes

Source
package.scala
extension [S, A](fold: ForgetFold[S, PartialResult, A])
def affineFold: PickFold[S, A]

The error-free view: a plain optics.PickFold with the same hits.

The error-free view: a plain optics.PickFold with the same hits.

Attributes

Source
PartialResult.scala
def either(s: S): Either[Errors, A]

The focus or the errors, as an Either — result(s).asEither.

The focus or the errors, as an Either — result(s).asEither.

Attributes

Source
PartialResult.scala
def getOption(s: S): Option[A]

The focus, dropping the errors.

The focus, dropping the errors.

Attributes

Source
PartialResult.scala
def result(s: S): Result[A]

The focus or chimney's errors, with their field paths.

The focus or chimney's errors, with their field paths.

Attributes

Source
PartialResult.scala
extension [A, B](i: Iso[A, B])
def toIso: BijectionIso[A, A, B, B]

This chimney Iso as an eo Iso: get = first, reverseGet = second. See Chimney.iso.

This chimney Iso as an eo Iso: get = first, reverseGet = second. See Chimney.iso.

Attributes

Source
package.scala
extension [S, T, A, F[_, _]](o: Optic[S, T, A, A, F])(using FF: ForgetfulFunctor[F])
inline def patch[P](p: P)(using pa: Patcher[A, P]): S => T

Patch the focus: o.modify(a => patcher.patch(a, p)). eo finds the part, chimney merges the patch's fields into it — lens[Order](_.customer).patch(CustomerPatch(email = "…"))(order). A miss (Prism / Optional) passes the S through untouched; a Traversal patches every focus. chimney derives the Patcher when none is in scope.

Patch the focus: o.modify(a => patcher.patch(a, p)). eo finds the part, chimney merges the patch's fields into it — lens[Order](_.customer).patch(CustomerPatch(email = "…"))(order). A miss (Prism / Optional) passes the S through untouched; a Traversal patches every focus. chimney derives the Patcher when none is in scope.

Attributes

Source
package.scala
extension [S, T, A, B, F[_, _]](o: Optic[S, T, A, B, F])(using FF: ForgetfulFunctor[F])
def transformFocus[C](using t: Transformer[C, B]): Optic[S, T, A, C, F]

Change the type you write at the focus: the new optic accepts a C and runs chimney's Transformer[C, B] to turn it into the B this optic writes back. Reads, the source and the result are unchanged — Optic[S, T, A, C] — so the focus reads as an A and is written as a C: lens[User](_.address).transformFocus[AddressView].replace(view)(user) writes a view where the lens expects an Address. Works on monomorphic optics (eo-generics' lenses); on a polymorphic one (Traversal.pEach[List, RawPrice, Price]), transformFocus[RawPrice] lets an edit of the RawPrice it reads be written back as a Price (.modify(r => RawPrice(r.cents * 2)) reprices and retypes in one write). The write-side counterpart of transformImage, which changes T; together they give Optic[S, U, A, C]. chimney derives the Transformer when none is in scope.

Change the type you write at the focus: the new optic accepts a C and runs chimney's Transformer[C, B] to turn it into the B this optic writes back. Reads, the source and the result are unchanged — Optic[S, T, A, C] — so the focus reads as an A and is written as a C: lens[User](_.address).transformFocus[AddressView].replace(view)(user) writes a view where the lens expects an Address. Works on monomorphic optics (eo-generics' lenses); on a polymorphic one (Traversal.pEach[List, RawPrice, Price]), transformFocus[RawPrice] lets an edit of the RawPrice it reads be written back as a Price (.modify(r => RawPrice(r.cents * 2)) reprices and retypes in one write). The write-side counterpart of transformImage, which changes T; together they give Optic[S, U, A, C]. chimney derives the Transformer when none is in scope.

A generic Optic, like Optic.innerProfunctor.lmap — but to is the original optic's own, so reads don't pay a carrier map they never use; only from maps the written Cs.

Attributes

Source
package.scala
extension [S, T, A, B, F[_, _]](o: Optic[S, T, A, B, F])(using FF: ForgetfulFunctor[F], FT: ForgetfulTraverse[F, Applicative])
def transformFocusPartial[C](using pt: PartialTransformer[C, B]): Optic[S, Result[T], A, C, F]

transformFocus for a PartialTransformer[C, B]: write a C, and get back the new T or the errors of every written C that didn't convert (all of them — errors accumulate across a Traversal's foci) — Optic[S, partial.Result[T], A, C]. The error paths are relative to each focus: chimney does not know where the optic pointed.

transformFocus for a PartialTransformer[C, B]: write a C, and get back the new T or the errors of every written C that didn't convert (all of them — errors accumulate across a Traversal's foci) — Optic[S, partial.Result[T], A, C]. The error paths are relative to each focus: chimney does not know where the optic pointed.

One pass, no per-focus partial.Result plumbing: the carrier's map converts every written C to B | Null — a failing one records its errors on the side and leaves null — and only if none failed does this optic's from rebuild the T, at which point every slot holds a real B. On any failure the mapped carrier is dropped and the errors returned: the underlying optic's write path never sees a null. The ForgetfulTraverse gate (otherwise unused) keeps this to carriers whose map runs eagerly, so every error is in before from is decided.

Attributes

Source
package.scala
extension [S, T, A, B, F[_, _]](o: Optic[S, T, A, B, F])
def transformImage[U](using t: Transformer[T, U]): Optic[S, U, A, B, F]

Change the result type: run chimney's Transformer[T, U] on whatever the optic writes back, turning its S => T side into S => U — the result-side counterpart of transformFocus. Every write lands in U: lens[User](_.name).transformImage[UserView].modify(_.trim)(user) edits a field and hands back the view. A miss (Prism / Optional) still produces a U — the untouched T, transformed. The focus side (S, A, B) is unchanged, so reads are the original optic's. chimney derives the Transformer when none is in scope.

Change the result type: run chimney's Transformer[T, U] on whatever the optic writes back, turning its S => T side into S => U — the result-side counterpart of transformFocus. Every write lands in U: lens[User](_.name).transformImage[UserView].modify(_.trim)(user) edits a field and hands back the view. A miss (Prism / Optional) still produces a U — the untouched T, transformed. The focus side (S, A, B) is unchanged, so reads are the original optic's. chimney derives the Transformer when none is in scope.

Core's Optic.outerProfunctor.rmap with a chimney transformer: the result is a generic Optic (the concrete class's fused overloads don't survive the remap).

Attributes

Source
package.scala
def transformImagePartial[U](using pt: PartialTransformer[T, U]): Optic[S, Result[U], A, B, F]

transformImage for a PartialTransformer[T, U]: every write hands back the U or the errors of turning the written T into one — "edit the DTO, then validate it into the domain".

transformImage for a PartialTransformer[T, U]: every write hands back the U or the errors of turning the written T into one — "edit the DTO, then validate it into the domain".

Attributes

Source
package.scala
extension [A, P](p: Patcher[A, P])
def toModify: Modify[A, A, Unit, P]

This patcher as a write-only optic: replace(patch) patches the A. See Chimney.patching.

This patcher as a write-only optic: replace(patch) patches the A. See Chimney.patching.

Attributes

Source
package.scala
extension [S, T](pt: PartialTransformer[S, T])
def toResultFold(failFast: Boolean = ...): ForgetFold[S, PartialResult, T]

This partial transformer as a fold into its result — a ForgetFold[S, PartialResult, T] that keeps chimney's errors through composition (see PartialResult). failFast = true stops at the first error, as chimney's transformFailFast does. See Chimney.resultFold.

This partial transformer as a fold into its result — a ForgetFold[S, PartialResult, T] that keeps chimney's errors through composition (see PartialResult). failFast = true stops at the first error, as chimney's transformFailFast does. See Chimney.resultFold.

Attributes

Source
package.scala
extension [S, T](t: Transformer[S, T])
def toGetter: Getter[S, T]

This transformer as a read: get(s) = t.transform(s). See Chimney.getter.

This transformer as a read: get(s) = t.transform(s). See Chimney.getter.

Attributes

Source
package.scala