My fs2 (was scalaz-stream) User Notes
CtrlK
  • Introduction
  • Foundations
  • Design Patterns
    • Category Theory Express Design Patterns
    • Category Theory
      • Semigroup
      • Monoid
      • Functor
      • Applicative
      • Products\/Coproducts
      • Monad
      • Free Monad
    • Category Theory for fs2
  • fs2 Core Model
    • Streams and Graphs
    • Composability
    • API
    • Effects
      • fs2 Effects
    • Smart Constructors and Combinators
  • fs2 Basics
    • Technical Setup
    • Simple Streams
    • Effectful Streams
    • Error Handling and Resource Management
    • Sinks
    • Channels and Exchanges
    • Combining Streams: Wye and Tee
    • Refs
  • Cookbook
    • Recipe: onFinish for Task
    • Recipe: Changing Seq[A] to A
    • Recipe: Debugging with toString
    • Recipe: Retrieving Web Pages
    • Recipe: Converting an Iterator to a Stream
    • Recipe: Data-Driven Stream
    • Recipe: Evaluate a Task Periodically
    • Recipe: Delay running a stream
    • Recipe: Stop an infinite Stream when you want to
    • Recipe: CSV Parsing with univocity
    • Recipe: CSV Parsing with node.js csv-parse using Readable => Stream
  • fs2 Examples
    • Akka Examples
    • Cafe
    • More Than One Stream
Powered by GitBook
On this page

Was this helpful?

  1. Cookbook

Recipe: Changing Seq[A] to A

Sometimes you have an "external world" process that gives you a Seq[A] but you need to process the data one A at a time.

You can define a pipe (until it comes standard in the library) like:

val toA = pipe.lift { seq => Stream.chunk(Chunk.seq(seq)) }

then you can do:

yourSourceOfSeqA.through(toA).toVector

This is equivalant to the following and is shorter:

yourSourceOfSeqA.flatMap(Stream.emits)
PreviousRecipe: onFinish for TaskNextRecipe: Debugging with toString

Last updated 5 years ago

Was this helpful?