Tuples transformations

This is mini project to transform tuple and its types.

It's Scala 3 only.

To install

libraryDependencies += "io.github.mercurievv.minuscles" % "tuples_transformers" % "0.1.0"

Use import

import io.github.mercurievv.minuscles.tuples.transformers.all.*

Let's create some input data:

val input: ((Int, Long), (String, (Boolean, Double, Char), (Float, Byte))) = ((1, 2L), ("3", (true, 0.5D, "6".charAt(0)), (0.7F, 0x8)))
// input: Tuple2[Tuple2[Int, Long], Tuple3[String, Tuple3[Boolean, Double, Char], Tuple2[Float, Byte]]] = (
//   (1, 2L),
//   ("3", (true, 0.5, '6'), (0.7F, 8))
// )

Now we will do some transformations:

Flattening, Nesting

val flatten: (Int, Long, String, Boolean, Double, Char, Float, Byte) = input.toFlatten
// flatten: Tuple8[Int, Long, String, Boolean, Double, Char, Float, Byte] = (
//   1,
//   2L,
//   "3",
//   true,
//   0.5,
//   '6',
//   0.7F,
//   8
// )
val flattenToNested: (Int, (Long, (String, (Boolean, (Double, (Char, (Float, Byte))))))) = flatToNestedR(flatten)
// flattenToNested: Tuple2[Int, Tuple2[Long, Tuple2[String, Tuple2[Boolean, Tuple2[Double, Tuple2[Char, Tuple2[Float, Byte]]]]]]] = (
//   1,
//   (2L, ("3", (true, (0.5, ('6', (0.7F, 8))))))
// )
//flatToNested method works correctly only with flattened tuples, but in such cases it should save some CPU
val nested: (Int, (Long, (String, (Boolean, (Double, (Char, (Float, Byte))))))) = input.toNestedR
// nested: Tuple2[Int, Tuple2[Long, Tuple2[String, Tuple2[Boolean, Tuple2[Double, Tuple2[Char, Tuple2[Float, Byte]]]]]]] = (
//   1,
//   (2L, ("3", (true, (0.5, ('6', (0.7F, 8))))))
// )

Two Elements Swap

Swapping 2 elements of tuple.

val swapped: (Int, Boolean, String, Long, Double, Char, Float, Byte) = flatten.swap(2, 4)
// swapped: Tuple8[Int, Boolean, String, Long, Double, Char, Float, Byte] = (
//   1,
//   true,
//   "3",
//   2L,
//   0.5,
//   '6',
//   0.7F,
//   8
// )