https://github.com/regadas/scio-cats
leverage cats type classes and data types in scio pipelines
https://github.com/regadas/scio-cats
apache-beam cats functional-programming scala scio
Last synced: 14 days ago
JSON representation
leverage cats type classes and data types in scio pipelines
- Host: GitHub
- URL: https://github.com/regadas/scio-cats
- Owner: regadas
- License: apache-2.0
- Created: 2020-03-24T13:19:19.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2025-03-06T00:27:15.000Z (8 months ago)
- Last Synced: 2025-04-02T06:11:22.737Z (7 months ago)
- Topics: apache-beam, cats, functional-programming, scala, scio
- Language: Scala
- Homepage: https://gh.regadas.io/scio-cats/latest/api/io/regadas/scio/cats/syntax/index.html
- Size: 1.09 MB
- Stars: 5
- Watchers: 2
- Forks: 2
- Open Issues: 31
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# scio-cats

[](./LICENSE)
[](https://maven-badges.herokuapp.com/maven-central/io.regadas/scio-cats_2.12)`scio-cats` is a collection of additional functions for [scio](https://github.com/spotify/scio) [SCollection](https://javadoc.io/static/com.spotify/scio-core_2.12/0.8.3/com/spotify/scio/values/SCollection.html) that leverage [cats](https://typelevel.org/cats) type classes and data types.
## Compatibility table
| 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 |## Quick Start
To use `scio-cats` add the following dependencies to your `build.sbt`:
```scala
libraryDependencies ++= Seq(
"io.regadas" %% "scio-cats" % ""
)
```### 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](https://gh.regadas.io/scio-cats/latest/api/io/regadas/scio/cats/syntax/SCollectionOps.html).
#### Maping and filtering of `F[A]`
```scala
// beforescioContext
.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]`
```scala
// 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`)
```scala
// 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
```