Created
June 12, 2019 16:32
-
-
Save justinhj/edaf1063d84167325466c863f5337ed1 to your computer and use it in GitHub Desktop.
Monoid composition
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
| // Tuples, integers and maps all have monoid | |
| // instances we can easily combine them | |
| @ val data = "Hello Hello This is some data data data yo" | |
| data: String = "Hello Hello This is some data data data yo" | |
| @ def step(word: String) = (1, word.length, Map(word -> 1)) | |
| defined function step | |
| @ def run(data: String) = data.split(" ").toList.map(step).combineAll | |
| defined function run | |
| @ run(data) | |
| res54: (Int, Int, Map[String, Int]) = (9, 34, Map("is" -> 1, "This" -> 1, "data" -> 3, "yo" -> 1, "Hello" -> 2, "some" -> 1)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment