   `(let [{~@(interleave bindings [:val :next-state]) ~@[]} ~state]
      ~@body))
 
-(defn- make-result-state
+(defn- make-state
   "Auxiliary function to avoid same map creation all over the place"
   [val next-state]
   {:val val :next-state next-state})

(defn unit-state
  "Generalized Unit function from section 6.5 of fpins"
  [a]
  (fn [rng] (make-result-state a rng)))

(defn map-via-flat-map-s
  "Generalized version of map-via-flat-map from exercise 6.9, for exercise 6.10"

        ;to make this working same way as in Scala/FPINS option
        nxt-rng (make-simple-rng-s nseed)
        n (.intValue (unsigned-bit-shift-right nseed 16))]
    (make-state n nxt-rng)))

(defn non-negative-int-fpins-s
  "FPINS variant of non-negative-int function, adapted to 'state' variant - haha - and I was thinking: Adding one is way too simple :)"
  [rng]
  (from-state (rng) :let [n nxt-rng]
            (if (< n 0)
              (make-state (- (inc n)) nxt-rng)
              (make-state n nxt-rng))))

;usage example
((state-sequence-fpins (repeat 5 non-negative-int-fpins-s)) (make-simple-rng-s 42))
