package com.easy.monads.examples;

import com.easy.monads.Reader;

import java.util.function.Function;

/**
 * Created by raja on 2/8/17.
 */
public class ReaderExamples {
    public static void main(String[] args) {
        example1();
    }

    private static void example1() {
        Reader<Integer, Integer> add2ThenMultiply5 =
                Reader.<Integer>ask()
                    .map(x -> x + 2)
                    .map(x -> x * 5);

        int result = add2ThenMultiply5.run(10);
        System.out.println(result);
    }
}

@@ -60,16 +60,54 @@
 eader;%0A%0A
+import java.util.function.BiFunction;%0A
 import j
@@ -134,16 +134,16 @@
 nction;%0A
-
 %0A/**%0A * 
@@ -268,16 +268,56 @@
 ple1();%0A
+        example2();%0A        example3();%0A
     %7D%0A%0A 
@@ -567,16 +567,17 @@
 un(10);%0A
+%0A
         
@@ -604,16 +604,1800 @@
 esult);%0A
+        //-%3E 60%0A    %7D%0A%0A    private static void example2() %7B%0A        BiFunction%3CString, Integer, Integer%3E doubleOrSqr = (operation, val) -%3E %7B%0A            switch (operation) %7B%0A                case %22square%22: return val * val;%0A                case %22double%22: return val + val;%0A                default: return val;%0A            %7D%0A        %7D;%0A%0A        int startVal = 3;%0A%0A        Reader%3CString, Integer%3E reader =%0A                Reader.%3CString%3Eask()%0A                        .map(config -%3E startVal)%0A                        .flatMap(val -%3E Reader.create(config -%3E doubleOrSqr.apply(config, val)))%0A                        .flatMap(val -%3E Reader.create(config -%3E doubleOrSqr.apply(config, val)))%0A                        .flatMap(val -%3E Reader.create(config -%3E doubleOrSqr.apply(config, val)));%0A%0A        int result1 = reader.run(%22square%22);%0A        int result2 = reader.run(%22double%22);%0A%0A        System.out.println(result1);%0A        //-%3E 6561%0A%0A        System.out.println(result2);%0A        //-%3E 24%0A    %7D%0A%0A    private static void example3() %7B%0A        Function%3CInteger, Integer%3E doubleNumer = num -%3E num + num;%0A        Function%3CInteger, Integer%3E squareNumber = num -%3E num * num;%0A        int startVal = 3;%0A%0A        Reader%3CFunction%3CInteger, Integer%3E, Integer%3E reader =%0A                Reader.%3CFunction%3CInteger, Integer%3E%3Eask()%0A                        .map(fn -%3E startVal)%0A                        .flatMap(val -%3E Reader.create(fn -%3E fn.apply(val)))%0A                        .flatMap(val -%3E Reader.create(fn -%3E fn.apply(val)))%0A                        .flatMap(val -%3E Reader.create(fn -%3E fn.apply(val)));%0A%0A        int result1 = reader.run(squareNumber);%0A        int result2 = reader.run(doubleNumer);%0A%0A        System.out.println(result1);%0A        //-%3E 6561%0A%0A        System.out.println(result2);%0A        //-%3E 24%0A
     %7D%0A%7D%0A

enhance Reader monad examples