Guest User

Untitled

a guest
Nov 17th, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. import io.vavr.Function1;
  2. import io.vavr.Tuple;
  3. import io.vavr.Tuple2;
  4. import io.vavr.collection.List;
  5. import io.vavr.Option;
  6.  
  7. import static io.vavr.collection.List.unfoldRight;
  8.  
  9. class A {}
  10. class B {}
  11. class Main {
  12. Function1<A, Option<Tuple2<B, A>>> f = (a) -> Option.of(Tuple.of(new B(), new A()));
  13. List<B> L0 = unfoldRight(new A(), f); // *
  14. List<B> L1 = unfoldRight(new A(), (a) -> Option.of(Tuple.of(new B(), new A()));
  15.  
  16. Option<Tuple2<B, A>> g(A a) { return Option.of(Tuple.of(new B(), new A())); }
  17. List<B> L2 = unfoldRight(new A(), (a) -> g(a)); // **
  18. }
  19.  
  20.  
  21. // * Compilation fails with: "Incompatible equality constraint: ? extends T and A"
  22.  
  23. // ** Compilation fails with: "Incompatible equality constraint: ? extends A and A"
  24.  
  25. static <T, U> List<U> unfoldRight(T seed, Function<? super T, Option<Tuple2<? extends U, ? extends T>>> f)
Add Comment
Please, Sign In to add comment