Created
November 18, 2025 13:32
-
-
Save marcinzh/92ed785e90ca9ff1eed613fd3a493ba5 to your computer and use it in GitHub Desktop.
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
| //> using scala "3.3.7" | |
| //> using dep "io.github.marcinzh::turbolift-core:0.122.0" | |
| import turbolift.!! | |
| import turbolift.effects.Choice | |
| import turbolift.Extensions._ | |
| @main def main = | |
| find_all_subsets(List(4, 5, 6)).foreach(println) | |
| def find_all_subsets(input: List[Int]) = | |
| input | |
| .flatMapEff(x => Choice(List(x), Nil)) | |
| .handleWith(Choice.handler) | |
| .run |
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
| //> using scala "3.3.7" | |
| //> using dep "io.github.marcinzh::turbolift-core:0.122.0" | |
| //> using dep "io.github.marcinzh::turbolift-bindless:0.122.0" | |
| import turbolift.!! | |
| import turbolift.bindless._ | |
| import turbolift.effects.Choice | |
| @main def main = | |
| find_all_subsets(List(4, 5, 6)).foreach(println) | |
| // More verbose, but probably clearer version: | |
| def find_all_subsets(input: List[Int]) = | |
| def loop(todo: List[Int], subset: List[Int]): List[Int] !! Choice = | |
| `do`: | |
| todo match | |
| case Nil => subset | |
| case x :: xs => | |
| val subset2 = Choice(subset :+ x, subset).! | |
| loop(xs, subset2).! | |
| loop(input, Nil) | |
| .handleWith(Choice.handler) | |
| .run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment