Advertisement
Guest User

Untitled

a guest
Jun 19th, 2024
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.81 KB | None | 0 0
  1.  void main() {
  2.         StreamF.of(1, 2, 3, 4)
  3.                 .apply(Main::up)
  4.                 .add(Stream::flatMap, Function.identity())
  5.                 .s
  6.                 .forEach(System.out::println);
  7.  
  8.     }
  9.  
  10.     public static <T> Stream<Stream<T>> up(Stream<T> s) {
  11.         return Stream.of(s);
  12.     }
  13.  
  14.     record StreamF<T>(Stream<T> s) {
  15.         @SafeVarargs
  16.         static <T> StreamF<T> of(T... t) {
  17.             return new StreamF<>(Stream.of(t));
  18.         }
  19.  
  20.         public <V> StreamF<V> add(BiFunction<Stream<T>, Function<T, Stream<V>>, Stream<V>> f, Function<T, Stream<V>> c) {
  21.             return new StreamF<>(f.apply(s, c));
  22.         }
  23.  
  24.         public <V> StreamF<V> apply(Function<? super Stream<T>, ? extends Stream<V>> c) {
  25.             return new StreamF<>(c.apply(s));
  26.         }
  27.     }
  28.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement