life-vest


License

License

GroupId

GroupId

lgbt.princess
ArtifactId

ArtifactId

life-vest_2.13
Last Version

Last Version

0.2.0
Release Date

Release Date

Type

Type

jar
Description

Description

life-vest
life-vest
Project URL

Project URL

https://github.com/NthPortal/life-vest
Project Organization

Project Organization

lgbt.princess
Source Code Management

Source Code Management

https://github.com/NthPortal/life-vest

Download life-vest_2.13

How to add to project

<!-- https://jarcasting.com/artifacts/lgbt.princess/life-vest_2.13/ -->
<dependency>
    <groupId>lgbt.princess</groupId>
    <artifactId>life-vest_2.13</artifactId>
    <version>0.2.0</version>
</dependency>
// https://jarcasting.com/artifacts/lgbt.princess/life-vest_2.13/
implementation 'lgbt.princess:life-vest_2.13:0.2.0'
// https://jarcasting.com/artifacts/lgbt.princess/life-vest_2.13/
implementation ("lgbt.princess:life-vest_2.13:0.2.0")
'lgbt.princess:life-vest_2.13:jar:0.2.0'
<dependency org="lgbt.princess" name="life-vest_2.13" rev="0.2.0">
  <artifact name="life-vest_2.13" type="jar" />
</dependency>
@Grapes(
@Grab(group='lgbt.princess', module='life-vest_2.13', version='0.2.0')
)
libraryDependencies += "lgbt.princess" % "life-vest_2.13" % "0.2.0"
[lgbt.princess/life-vest_2.13 "0.2.0"]

Dependencies

compile (2)

Group / Artifact Type Version
org.scala-lang : scala-library jar 2.13.4
com.typesafe.akka : akka-stream_2.13 jar 2.6.10

test (1)

Group / Artifact Type Version
org.scalatest : scalatest_2.13 jar 3.2.2

Project Modules

There are no modules declared in this project.

life-vest

Build Status Coverage Status Maven Central Versioning Docs

A library for treating stream and non-stream transformations uniformly when processing data with Akka Streams. The name is a pun on a life vest being the "uniform" of someone working in a stream or river.

Add to Your sbt Build

Scala 2.13

libraryDependencies += "lgbt.princess" %% "life-vest" % "0.2.0"

Usage

Wrapping collections, Options and Sources

The first enumerator in the for comprehension must be wrapped in a Streamable(...), as well as each subsequent enumerator up through the last enumerator that is a Source. See the following examples:

import akka.stream.scaladsl.Source
import lgbt.princess.lifevest.Streamable

// four enumerators need to be wrapped in `Streamable(...)` because
// the last of them is a `Source`.
def foo: Streamable[Int] = for {
  i <- Streamable(Set(1, 2, 3, 4, 5))
  jStr <- Streamable(List("1", "2"))
  j = jStr.toInt
  k <- Streamable(Some(1))
  x <- Streamable(Source(List(1, 2, 3)))
  if i + x > 6
  y <- Vector(6, 7)
} yield i + j + k + x + y

// only the first enumerator needs to be wrapped in `Streamable(...)`
def bar: Streamable[Int] = for {
  i <- Streamable(Source(List(1, 2, 3, 4, 5)))
  jStr <- List("1", "2")
  j = jStr.toInt
  k <- Some(1).toList
  x <- Set(1, 2, 3)
  if i + x > 6
  y <- Vector(6, 7)
} yield i + j + k + x + y

The requirement to wrap multiple enumerators in Streamable(...) in some cases is because collections and Option do not have .flatMap methods taking a function returning a Source. This is similar to how you sometimes need to call .toList on an Option when flatMaping with collections, because Option#flatMap takes a function returning an Option, not a function returning a collection.

Creating Streamables directly from elements

Besides creating Streamables from collections, Options and Sources, you can create Streamables directly from elements. You can create a Streamable containing a single element using Streamable.single, and a Streamable from an arbitrary number of elements using the Streamable.elems varargs method. There is also a Streamable.empty method for returning a Streamable with no elements.

Integrating a Streamable into an Akka Stream

A Streamable can be easily flattened into a stream by calling .toSource on it.

import akka.stream.scaladsl.Flow
import lgbt.princess.lifevest.Streamable

def processJson(json: Json): Streamable[Result] = ???

val processingFlow: Flow[Result] = Flow[Json].flatMapConcat(json => processJson(json).toSource)

Versions

Version
0.2.0
0.1.0