Created
November 24, 2020 19:50
-
-
Save jchapuis/87e3ca6327592f8307dee685a1579442 to your computer and use it in GitHub Desktop.
Generate all possible combinations of letters in scala lazily
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
| implicit class RichLazyStringList(list: LazyList[String]) { | |
| def productWith(other: LazyList[String]): LazyList[String] = | |
| for { | |
| a <- list | |
| b <- other | |
| } yield a + b | |
| } | |
| LazyList | |
| .from(1) | |
| .map(charCount => LazyList.fill(charCount)(LazyList.from('a' to 'z').map(_.toString))) | |
| .flatMap(_.reduceLeft(_.productWith(_))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment