package ixee.cryptopals.utils object StreamUtils { implicit class RichStream[A](x: Stream[A]) { def splice(other: Stream[A]): Stream[A] = { var i = 0 val selfIter = x.iterator val otherIter = other.iterator Stream.continually { i = i + 1 if (i % 2 == 0) { otherIter.next } else { selfIter.next } } } def spliceEvery(n: Int)(other: Stream[A]): Stream[A] = { var i = 0 val selfIter = x.iterator val otherIter = other.iterator Stream.continually { i = i + 1 if (i % (n + 1) == 0) { otherIter.next } else { selfIter.next } } } } }