Skip to content

ducktape 0.2.3

Compare
Choose a tag to compare
@arainko arainko released this 15 Jul 20:54
· 96 commits to series/0.2.x since this release
54d7942

ducktape 0.2.3

This release brings the ability to transform tuples in all kind of ways (tuple-to-tuple, product-to-tuple, tuple-to-product), so stuff like this is now possible:

import io.github.arainko.ducktape.*

case class Source(field1: Int, field2: List[Int], field3: Int, field4: Int)

Source(1, List(2, 2, 2), 3, 4).to[(Int, Vector[Int], Option[Int])]
// res18: Tuple3[Int, Vector[Int], Option[Int]] = (
//   1,
//   Vector(2, 2, 2),
//   Some(value = 3)
// )

(1, List(2, 2, 2), 3, 4).to[Source]
// res19: Source = Source(
//  field1 = 1,
//  field2 = List(2, 2, 2),
//  field3 = 3,
//  field4 = 4
// )

The newly added ability for F-unwrapping (i.e. lifting the wrapper type into the 'outside' of a fallible transformation) in conjuction with tuple transformation enables some fantastic use cases for match types, like the ability to 'traverse' a tuple:

import io.github.arainko.ducktape.*

val source =
  (
    Right(1),
    Right("str"),
    Right(List(3, 3, 3)),
    Right(4)
  )

Mode.Accumulating.either[String, List].locally {
  source.fallibleTo[Tuple.InverseMap[source.type, Mode.current.Self]]
}
// res0: Either[List[String], *:[Int, *:[String, *:[List[Int], *:[Int, EmptyTuple]]]]] = Right(
//   value = (1, "str", List(3, 3, 3), 4)
// )

...which is really just the tip of the iceberg - stay tuned for a more in-depth look on how this mechanism can be leveraged in other use cases.

Head on over to the docs on configuring tuples to see how the configuration DSL works with tuples.

What's Changed

Full Changelog: v0.2.2...v0.2.3