This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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), |
NewerOlder