Skip to content

marcinzh/beam

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Maven Central

Beam

Purely functional streams, implemented with algebraic effects and handlers.

 

  • ⚗️ 🔬 🧪   𝑷𝑹𝑶𝑻𝑶𝑻𝒀𝑷𝑬   🚧 WIP 🚧
  • Uses Scala 3.
  • Uses Turbolift as effect system.

 

Examples

Runnable with scala-cli. Turbolift requires ⚠️Java 11⚠️ or newer.

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

//> using scala "3.3.3"
//> using dep "io.github.marcinzh::beam-core:0.8.0"
//> using dep "io.github.marcinzh::turbolift-bindless:0.98.0"
import turbolift.!!
import turbolift.effects.Console
import turbolift.bindless._
import beam._

@main def main =
  val fibos: 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)

  fibos.take(20).toVector
  .tapEff(xs => Console.println(xs.mkString(" ")))
  .handleWith(Console.handler)
  .runIO

See also examples folder. Runnable with sbt:

sbt examples/run

Releases

No releases published

Packages

No packages published

Languages