Last active
July 31, 2020 22:14
-
-
Save danieldietrich/08d1321ca1b9f47aac61429c07ab9193 to your computer and use it in GitHub Desktop.
FizzBuzz with Vavr using Either
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
import static io.vavr.API.*; | |
import io.vavr.collection.Iterator; | |
import io.vavr.control.Either; | |
public class FizzBuzz { | |
public static void main(String[] args) { | |
var fizzBuzz = Iterator.from(1).map(i -> | |
(i % 15 == 0) ? Right("FizzBuzz") : | |
(i % 3 == 0) ? Right("Fizz") : | |
(i % 5 == 0) ? Right("Buzz") : Left(i) | |
); | |
fizzBuzz.drop(200).take(10).forEach(System.out::println); | |
} | |
} |
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
Right(Fizz) | |
Left(202) | |
Left(203) | |
Right(Fizz) | |
Right(Buzz) | |
Left(206) | |
Right(Fizz) | |
Left(208) | |
Left(209) | |
Right(FizzBuzz) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment