Advertisement
dburyak

skittles monad - class knows about sub-classes

Aug 6th, 2022
1,952
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.77 KB | None | 0 0
  1. package skittles.monad.knowsimpl;
  2.  
  3. import javax.lang.model.type.NullType;
  4. import java.util.function.Function;
  5.  
  6. public abstract class Monad<T, E> {
  7.     private final T value;
  8.  
  9.     public Monad(T value) {
  10.         this.value = value;
  11.     }
  12.  
  13.     public T extract() {
  14.         return this.value;
  15.     }
  16.  
  17.     public Monad<NullType, E> bind(Function<T, Monad<NullType, E>> f) {
  18.         return f.apply(value);
  19.     }
  20.  
  21.     public Monad<NullType, E> sequencer(Monad<NullType, E> b) {
  22.         return bind(__ -> b);
  23.     }
  24.  
  25.     public static <T, E> Monad<T, E> create(T value) {
  26.         return new Kek<>(value);
  27.     }
  28. }
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35. package skittles.monad.knowsimpl;
  36.  
  37. public class Kek<T, E> extends Monad<T, E> {
  38.     public Kek(T value) {
  39.         super(value);
  40.     }
  41. }
  42.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement