tofu.internal.FoldableStream.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of tofu-kernel_3 Show documentation
Show all versions of tofu-kernel_3 Show documentation
Opinionated set of tools for functional programming in Scala
package tofu.internal
import cats.Foldable
import cats.Eval
sealed trait FoldableStream[+A]
object FoldableStream {
def from[F[_], A](fa: F[A])(implicit F: Foldable[F]): FoldableStream[A] =
F.foldRight(fa, emptyE[A])((h, t) => Eval.always(Cons(h, t))).value
val emptyNothing: Eval[FoldableStream[Nothing]] = Eval.now(Empty)
def emptyE[A]: Eval[FoldableStream[A]] = emptyNothing
case object Empty extends FoldableStream[Nothing]
final case class Cons[+A](a: A, tail: Eval[FoldableStream[A]]) extends FoldableStream[A]
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy