Package fj.data

Class State<S,​A>


  • public final class State<S,​A>
    extends java.lang.Object
    • Method Detail

      • unit

        public static <S,​A> State<S,​A> unit​(F<S,​P2<S,​A>> runF)
      • init

        public static <S> State<S,​S> init()
      • units

        public static <S> State<S,​S> units​(F<S,​S> f)
      • dup

        private static <S> P2<S,​S> dup​(S s)
      • constant

        public static <S,​A> State<S,​A> constant​(A a)
      • gets

        public static <S,​A> State<S,​A> gets​(F<S,​A> f)
      • put

        public static <S> State<S,​Unit> put​(S s)
      • modify

        public static <S> State<S,​Unit> modify​(F<S,​S> f)
      • flatMap

        public static <S,​A,​B> State<S,​B> flatMap​(State<S,​A> ts,
                                                                   F<A,​State<S,​B>> f)
      • sequence

        public static <S,​A> State<S,​List<A>> sequence​(List<State<S,​A>> list)
        Evaluate each action in the sequence from left to right, and collect the results.
      • traverse

        public static <S,​A,​B> State<S,​List<B>> traverse​(List<A> list,
                                                                          F<A,​State<S,​B>> f)
        Map each element of a structure to an action, evaluate these actions from left to right and collect the results.
      • suspended

        private static <S,​A> State<S,​A> suspended​(F<S,​Trampoline<P2<S,​A>>> runF)
      • run

        public P2<S,​A> run​(S s)
      • eval

        public A eval​(S s)
      • exec

        public S exec​(S s)
      • gets

        public State<S,​S> gets()
      • map

        public <B> State<S,​B> map​(F<A,​B> f)
      • mapState

        public <B> State<S,​B> mapState​(F<P2<S,​A>,​P2<S,​B>> f)
      • withs

        public State<S,​A> withs​(F<S,​S> f)
      • bind

        public <B> State<S,​B> bind​(F<A,​State<S,​B>> f)
        Bind the given function across this state.
        Type Parameters:
        B - the type of the output value
        Parameters:
        f - the given function
        Returns:
        the state
      • flatMap

        public <B> State<S,​B> flatMap​(F<A,​State<S,​B>> f)
        Bind the given function across this state.
        Type Parameters:
        B - the type of the output value
        Parameters:
        f - the given function
        Returns:
        the state