Skip to content

Instantly share code, notes, and snippets.

View krasserm's full-sized avatar

Martin Krasser krasserm

View GitHub Profile
// Applicative functors (Haskell - Scalaz comparison)
val mult = (_:Int) * (_:Int)
val multc = mult.curried
// (*) <$> Just 3 <*> Just 5
some(5) <*> some(3) ∘ multc
// pure (*) <*> Just 3 <*> Just 5
some(5) <*> (some(3) <*> multc.pure[Option])
def merge(a: Stream[Int], b: Stream[Int], c: Stream[Int]): Stream[Int] = {
val m = a.head min b.head min c.head
Stream.cons(m, merge(
if (m < a.head) a else a.tail,
if (m < b.head) b else b.tail,
if (m < c.head) c else c.tail))
}
def hamming: Stream[Int] = Stream.cons(1, merge(
hamming.map(_ * 2),