scio-cats
is a collection of additional functions for scio SCollection that leverage cats type classes and data types.
scio-cats | scio |
---|---|
0.1.3 | 0.9.3 |
0.1.2 | 0.9.0 |
0.1.1 | 0.8.4 |
0.1.0 | 0.8.3 |
To use scio-cats
add the following dependencies to your build.sbt
:
libraryDependencies ++= Seq(
"io.regadas" %% "scio-cats" % "<version>"
)
These are just few examples that show some of nicities of the added functions. Most of these functions have scaladoc with an example. Have a look.
// before
scioContext
.parallelize(Seq(Some(1), None, Some(2)))
.map(_.map(_ + 1)) // Some(2), None, Some(3)
.filter(_.exists(_ > 2)) // Some(3)
// after
import cats.implicits._
import io.regadas.scio.cats.syntax._
scioContext
.parallelize(Seq(Some(1), None, Some(2)))
.map_(_ + 1) // Some(2), None, Some(3)
.filter_(_ > 2) // Some(3)
// before
scioContext
.parallelize(Seq(Some(1), None, Some(2)))
// here you could also use `cats` but it doesn't look as nice
// .map(_.tupleRight(1))
.map(_.map(_ -> 1)) // Some((1, 1)), Some((2, 1))
// after
import cats.implicits._
import io.regadas.scio.cats.syntax._
scioContext
.parallelize(Seq(Some(1), None, Some(2)))
// tupleLeft is also available
.tupleRight(1) // Some((1, 1)), Some((2, 1))
// before
scioContext
.parallelize(Seq(Some(1), None, Some(2)))
.debug() // it will use toString()
// after
import cats.implicits._
import io.regadas.scio.cats.syntax._
scioContext
.parallelize(Seq(Some(1), None, Some(2)))
.showStdOut // leverages Show type class