Advertisement
dburyak

Untitled

Aug 6th, 2022
1,264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.47 KB | None | 0 0
  1. import javax.lang.model.type.NullType;
  2. import java.util.function.Function;
  3.  
  4. public class Monad<T, E> {
  5.     private final T value;
  6.  
  7.     public Monad(T value) {
  8.         this.value = value;
  9.     }
  10.  
  11.     public T extract() {
  12.         return this.value;
  13.     }
  14.  
  15.     public Monad<NullType, E> bind(Function<T, Monad<NullType, E>> f) {
  16.         return f.apply(value);
  17.     }
  18.  
  19.     public Monad<NullType, E> sequencer(Monad<NullType, E> b) {
  20.         return bind(__ -> b);
  21.     }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement