Skip to content

Instantly share code, notes, and snippets.

@sheki
Created January 24, 2012 17:43
Show Gist options
  • Select an option

  • Save sheki/1671444 to your computer and use it in GitHub Desktop.

Select an option

Save sheki/1671444 to your computer and use it in GitHub Desktop.
def merge(as: Stream[Int], bs: Stream[Int], cs: Stream[Int]): Stream[Int] = {
val h = as.head min bs.head min cs.head
Stream.cons(
h,
merge(as dropWhile {_ == h}, bs dropWhile {_ == h}, cs dropWhile {_ == h})
)
}
This function produces a stream containing a constant times each value from another:
val prod = (k: Int) => (s: Stream[Int]) => s.map{k * _}
With those definitions in hand…
def hamming: Stream[Int] = Stream.cons(
1,
merge(prod(2)(hamming), prod(3)(hamming), prod(5)(hamming))
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment