   "flatMap for exercise 6.8 from FPINS but generalized to state for exercise 6.10"
   [f g]
   #(from-state (f %) :let [v s]
-             ((g v) s)))
+               ((g v) s)))
 
 (defn unit-state
   "Generalized Unit function from section 6.5 of fpins"

  [fs]
  (reduce                                                   ;check out comment below to see why I've used reduce instead of fold-right
    #(map2-rng % %2 (fn [a b]
                       (if (vector? a)
                         (conj a b)
                         [a b])))
    (first fs)
    (rest fs)))
;I am using reduce because my fold-right from strictness-and-laziness is not proper scala translation

  "sequence function for exercise 6.7 FPINS variant"
  [fs]
  (fpinscala.strictness-and-laziness/fold-right             ;Notice that this variant is using fold-right
    (unit-state '())                                        ;Check out that "unit-produced" function is used as z value (now - it wouldn't be really
    #(map2-via-flat-map-s % %2 (fn [a b] (cons a b)))       ;correct to say it is "initial" but rather neutral (or terminating?) element
    fs))                                                    ;UPDATE (25.11.2015) Check out wikipedia about monad, it is actually "return" also
;called "unit" operation of a monad

(declare simple-rng-s)

