Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Maven Central Version javadoc

Beam

Purely functional streams for Scala 3.  

  • Implemented with algebraic effects and handlers, provided by Turbolift.
  • The API of Stream type is inspired by FS2 and ZIO.
  • The use of algebraic effects and handlers for implementing streams is inspired by Stream from Unison language.

🚧 WIP 🚧  

Examples

Runnable with scala-cli.

Important

Turbolift requires Java 11 or newer.

//> using scala "3.3.7"
//> using dep "io.github.marcinzh::beam-core:0.20.0"
//> using dep "io.github.marcinzh::turbolift-bindless:0.124.0"
package examples
import turbolift.!!
import turbolift.effects.Console
import turbolift.bindless._
import beam._

/** Stuttering Fibonacci sequence: when the number is even, emit it twice. */

@main def ex01_sourceEffect =
  val stream: Stream[Long, Any] =
    Source: fx =>
      def loop(a: Long, b: Long): Unit !! fx.type =
        `do`:
          fx.emit(a).!
          if a % 2 == 0 then fx.emit(a).!
          loop(b, a + b).!
      loop(1, 1)

  stream
    .take(20)
    .foreachEff(i => Console.println(i.toString))
  .handleWith(Console.handler)
  .runIO

See also examples folder.

About

Streams using Algebraic Effects and Handlers

Topics

Resources

Stars

2 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages