Created
March 14, 2019 22:43
-
-
Save mchmielarz/d7ee4c0d7fa6b9b448eee60f11e581d8 to your computer and use it in GitHub Desktop.
for-comprehension: Comparing combining data with List.zip and for-comprehension
This file contains 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
// List.zip/zipWith | |
final Option<String> option = Option.of("value"); | |
final Either<String, String> either = Either.right("yay"); | |
final Iterator<Integer> integers = Iterator.tabulate(5, value -> value + 1); | |
final List<Tuple2<Integer, String>> zipped = integers.zip(either); | |
final List<Tuple3<Integer, String, String>> zipped3 = zipped | |
.zip(option) | |
.map(e -> Tuple.of(e._1._1, e._1._2, e._2)); | |
//the same with for-comprehension | |
final Iterator<Tuple3<Integer, String, String>> combined = API.For( | |
integers, | |
either, | |
option | |
) | |
.yield(Tuple::of); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment