Giter Club home page Giter Club logo

beam's Introduction

Maven Central

Beam

Purely functional streams, implemented with algebraic effects and handlers.

Data processing is done with entities such as Stream, Pipe and Sink, which can employ arbitrary sets of effects.

Optionally, they can be constructed as coroutines.

 

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

 

Example

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

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

@main def main =
  val fibos: Stream[Long, Any] =
    Stream.coroutine: fx =>
      def loop(a: Long, b: Long): Unit !! fx.type =
        for
          _ <- fx.write(a)
          _ <- !!.when(a % 2 == 0)(fx.write(a))
          _ <- loop(b, a + b)
        yield ()
      loop(1, 1)

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

beam's People

Contributors

marcinzh avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.