All Downloads are FREE. Search and download functionalities are using the official Maven repository.

pimpathon.stream.scala Maven / Gradle / Ivy

The newest version!
package pimpathon

import pimpathon.function._


object stream {
  def cond[A](cond: Boolean, stream: ⇒ Stream[A]): Stream[A] = if (cond) stream else Stream.empty[A]
  def continuallyWhile[A](elem: ⇒ A)(p: Predicate[A]): Stream[A] = Stream.continually(elem).takeWhile(p)

  implicit def streamPimps[A](stream: Stream[A]): StreamPimps[A] = new StreamPimps[A](stream)

  class StreamPimps[A](val value: Stream[A]) {
    def uncons[B](empty: ⇒ B, nonEmpty: Stream[A] ⇒ B): B = if (value.isEmpty) empty else nonEmpty(value)

    def tailOption: Option[Stream[A]] = uncons(None, _ ⇒ Some(value.tail))
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy