Skip to content

Instantly share code, notes, and snippets.

@clayrat
Created December 18, 2013 12:16
Show Gist options
  • Save clayrat/8021328 to your computer and use it in GitHub Desktop.
Save clayrat/8021328 to your computer and use it in GitHub Desktop.
def skipLast[T](s: Stream[T], c: Int): Stream[T] = {
var buf = s take c
s drop c flatMap { x =>
val h = if (!buf.isEmpty)
Stream(buf.head) else Stream()
buf = buf.drop(1) :+ x
h
}
}
@dimchansky
Copy link

def skipLast[T](stream: Stream[T], count: Int): Stream[T] = {
  val q = scala.collection.mutable.Queue[T]()
  for(
    i <- stream
    if ((q += i).size > count)
  ) yield q.dequeue()
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment