FranklinChen / scala-fair-stream

Scala implementation of fair backtracking stream

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Fair backtracking stream monad, in Scala

Continuous Integration

Code translated from Oleg's original Haskell.

Notes about writing code for laziness

This library illustrates the use of the Cats library to support different evaluation strategies, such as call-by-need. For example:

  def map[B](f: A => B): FairStream[B] = this match {
    case Empty() => empty
    case One(a) => FairStream(f(a))
    case Cons(a, t) => Cons(f(a), Wait(Later(t map f)))
    case Wait(next) => Wait(next.map(_ map f))
  }

uses Later from Eval.

About

Scala implementation of fair backtracking stream


Languages

Language:Scala 100.0%