regadas / scio-cats

leverage cats type classes and data types in scio pipelines

Website GitHub

scio-cats

build GitHub license Maven Central

scio-cats is a collection of additional functions for scio SCollection that leverage cats type classes and data types.

Compatibility table

scio-cats scio
0.1.2 0.9.0
0.1.1 0.8.4
0.1.0 0.8.3

Quick Start

To use scio-cats add the following dependencies to your build.sbt:

libraryDependencies ++= Seq(
  "io.regadas" %% "scio-cats" % "<version>"
)

Examples

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.

Maping and filtering of F[A]

// 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)

Creating tuples over F[A]

// 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))

Output to the console (similar to debug)

// 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