arainko / ducktape

Automatic and customizable compile time transformations between similar case classes and sealed traits/enums, essentially a thing that glues your code. Scala 3 only. Or is it duct 🤔
https://arainko.github.io/ducktape/
Other
405 stars 7 forks source link

Allow F-unwrapping transformations #178

Closed arainko closed 3 months ago

arainko commented 4 months ago

This could especially come in handy when working with tuples, i.e.:

import io.github.arainko.ducktape.*
import scala.util.chaining.*

val unwrapped: Option[(Int, Int, Int, Int)] =
  Mode.FailFast.option.locally {
    (
      Option(1),
      Option(2),
      Option(3),
      Option(4)
    ).pipe(source => source.fallibleTo[Tuple.InverseMap[source.type, Option])
}

Mode.Accumulating would only be able to do non-fallible transformations after unwrapping the F since it doesn't have a .flatMap transformation which could allow it to sequence more fallible transformations afterwards. That doesn't apply to Mode.FailFast.

arainko commented 3 months ago

completed in #182