diff options
Diffstat (limited to 'src/lux/base.clj')
-rw-r--r-- | src/lux/base.clj | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/lux/base.clj b/src/lux/base.clj index a507362f9..c9050a7e6 100644 --- a/src/lux/base.clj +++ b/src/lux/base.clj @@ -614,6 +614,28 @@ ))) )) +(defn try-all-% [prefix monads] + (|case monads + ($Nil) + (fail "There are no alternatives to try!") + + ($Cons m monads*) + (fn [state] + (let [output (m state)] + (|case [output monads*] + [($Right _) _] + output + + [_ ($Nil)] + output + + [($Left ^String error) _] + (if (.contains error prefix) + ((try-all-% prefix monads*) state) + output) + ))) + )) + (defn exhaust% [step] (fn [state] (|case (step state) |