aboutsummaryrefslogtreecommitdiff
path: root/src/lang/util.clj
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/lang/util.clj16
1 files changed, 11 insertions, 5 deletions
diff --git a/src/lang/util.clj b/src/lang/util.clj
index cdfa8555d..e2edfb550 100644
--- a/src/lang/util.clj
+++ b/src/lang/util.clj
@@ -59,14 +59,14 @@
(match (monad state)
[::ok [?state ?head]]
(do ;; (prn 'repeat-m/?state ?state)
- (match ((repeat-m monad) ?state)
- [::ok [?state* ?tail]]
- (do ;; (prn 'repeat-m/?state* ?state*)
- (return* ?state* (cons ?head ?tail)))))
+ (match ((repeat-m monad) ?state)
+ [::ok [?state* ?tail]]
+ (do ;; (prn 'repeat-m/?state* ?state*)
+ (return* ?state* (cons ?head ?tail)))))
[::failure ?message]
(do ;; (println "Failed at last:" ?message)
- (return* state '())))))
+ (return* state '())))))
(defn try-all-m [monads]
(fn [state]
@@ -89,6 +89,12 @@
outputs (map-m f (rest inputs))]
(return (conj outputs output)))))
+(defn reduce-m [f init inputs]
+ (if (empty? inputs)
+ (return init)
+ (exec [init* (f init (first inputs))]
+ (reduce-m f init* (rest inputs)))))
+
(defn apply-m [monad call-state]
(fn [state]
;; (prn 'apply-m monad call-state)