Class Reader<C,​A>

  • Type Parameters:
    C - the type of the context
    A - the type of the value

    public class Reader<C,​A>
    extends Object
    Class representing Reader monad. A reader monad reads a value from the context and returns a value
    Author:
    Herbert Praehofer
    • Field Detail

      • fn

        private Function<C,​A> fn
        The reader function
    • Constructor Detail

      • Reader

        private Reader​(Function<C,​A> fn)
        Constructor setting the reader function.
        Parameters:
        fn - the reader function
    • Method Detail

      • of

        public static <C,​A> Reader<C,​A> of​(Function<C,​A> fn)
        Creates a reader monad from a reader function.
        Type Parameters:
        C - the type of the context
        A - the type of the value
        Parameters:
        fn - the reader function
        Returns:
        the reader monad
      • apply

        public A apply​(C context)
        Applies the reader function to a context.
        Parameters:
        context - the context
        Returns:
        the read value
      • flatMap

        public <B> Reader<C,​B> flatMap​(Function<? super A,​Reader<C,​? extends B>> mapper)
        Monad operator.
        Type Parameters:
        B - the result type of the created reader monad.
        Parameters:
        mapper - the mapping function
        Returns:
        the resulting reader monad