Skip to content

Instantly share code, notes, and snippets.

@danieldietrich
Last active July 31, 2020 22:14
Show Gist options
  • Save danieldietrich/08d1321ca1b9f47aac61429c07ab9193 to your computer and use it in GitHub Desktop.
Save danieldietrich/08d1321ca1b9f47aac61429c07ab9193 to your computer and use it in GitHub Desktop.
FizzBuzz with Vavr using Either
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);
}
}
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