Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Java 8: Lambdas, Monads and Java Collections

Java 8: Lambdas, Monads and Java Collections

Presented during Confitura 2015

Grzegorz Piwowarek

July 06, 2015
Tweet

More Decks by Grzegorz Piwowarek

Other Decks in Programming

Transcript

  1. lambda expressions x -> x + 1 () -> 42

    () -> {return 42;} (x, y) -> {} () -> {}
  2. Function<T, R>, BiFunction<T,U,R> Consumer<T> extends Function<T,Void> Supplier<T> extends Function<Void, T>

    Predicate<T> extends Function<T, Boolean> UnaryOperator<T> extends Function<T, T> BinaryOperator<T> extends BiFunction<T,T,T>
  3. Function<T, R>, BiFunction<T,U,R> Consumer<T> extends Function<T,Void> Supplier<T> extends Function<Void, T>

    Predicate<T> extends Function<T, Boolean> UnaryOperator<T> extends Function<T, T> BinaryOperator<T> extends BiFunction<T,T,T>
  4. Function<T, R>, BiFunction<T,U,R> Consumer<T> extends Function<T,Void> Supplier<T> extends Function<Void, T>

    Predicate<T> extends Function<T, Boolean> UnaryOperator<T> extends Function<T, T> BinaryOperator<T> extends BiFunction<T,T,T>
  5. Function<T, R>, BiFunction<T,U,R> Consumer<T> extends Function<T,Void> Supplier<T> extends Function<Void, T>

    Predicate<T> extends Function<T, Boolean> UnaryOperator<T> extends Function<T, T> BinaryOperator<T> extends BiFunction<T,T,T>
  6. Function<T, R>, BiFunction<T,U,R> Consumer<T> extends Function<T,Void> Supplier<T> extends Function<Void, T>

    Predicate<T> extends Function<T, Boolean> UnaryOperator<T> extends Function<T, T> BinaryOperator<T> extends BiFunction<T,T,T>
  7. ...

  8. type: M<T> "unit": T -> M<T> "bind": M<T>.bind(T -> M<U>)

    = M<U> MONAD "bind": M<T>.bind(T -> U)= M<U>
  9. type: M<T> "unit": T -> M<T> "bind": M<T> bind(T ->

    M<U>) = M<U> MONAD "bind": M<T>.bind(T -> U)= M<U>
  10. "bind": M<T> bind(T -> U)= M<U> What if U: M<?>

    ? http://www.ivanaborovnjak.com/project/box-in-a-box/
  11. REFERENCES: -"MONADIC JAVA" BY MARIO FUSCO -"WHAT'S WRONG WITH JAVA

    8" BY PIERRE-YVES SAUMONT -WWW.ORACLE.COM -"A FISTFUL OF MONADS" - LEARN YOU A HASKELL FOR GREAT GOOD