Skip to content

Access context information in transformer #442

Answered by MateuszKubuszok
jeengbe asked this question in Q&A
Discussion options

You must be logged in to vote

Hi,

When it comes to reading the current field path, then currently Chimney does not provide such a feature - mostly because this error-path is built in the runtime, e.g. when we are building error paths in PartialTransformers:

case class Foo(bar: Bar)
case class Bar(a: String)

case class Baz(bar: Bar2)
case class Bar2(a: Int)

implicit val bars: PartialTransformer[Bar, Bar2] = PartialTransformer { bar =>
  partial.Result
    .fromCatching(bar.a.toInt)
    .prependErrorPath(partial.PathElement.Accessor("a"))
    .map(a => Bar2(a))
}

implicit val fooBar: PartialTransformer[Foo, Baz] = PartialTransformrt { foo =>
  bars.transform(foo.bar)
    .prependErrorPath(partial.PathElement.Accessor("

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@jeengbe
Comment options

@MateuszKubuszok
Comment options

@jeengbe
Comment options

Answer selected by jeengbe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants