Created
June 12, 2019 18:13
-
-
Save justinhj/83adc80b4fbffc44497dcbe1ccedf433 to your computer and use it in GitHub Desktop.
Comonad
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
| // Comonad is the dual of Monad | |
| // example for non empty list, extract is the head of the list | |
| // coflatMap gives you successive lists from the whole list, the tail, the tail of that | |
| // and you must return a single value for each list... | |
| @ Comonad[NonEmptyList].extract(NonEmptyList.of(1,2,3)) | |
| res26: Int = 1 | |
| @ Comonad[NonEmptyList].extract(NonEmptyList.of(1)) | |
| res27: Int = 1 | |
| @ Comonad[NonEmptyList].coflatMap(NonEmptyList.of(1,2,3,4,5,6,7,8,9,10)){_.head} | |
| res28: NonEmptyList[Int] = NonEmptyList(1, List(2, 3, 4, 5, 6, 7, 8, 9, 10)) | |
| @ Comonad[NonEmptyList].coflatMap(NonEmptyList.of(1,2,3,4,5,6,7,8,9,10)){_.size} | |
| res29: NonEmptyList[Int] = NonEmptyList(10, List(9, 8, 7, 6, 5, 4, 3, 2, 1)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment