jeaye/orchestra

Interesting use case

Closed this issue · 1 comments

orchestra may have an interesting synergy with packages like cats.

Example:

(defmacro exception-of?
  "Construct predicate function for testing exception monad value.
  The predicate returns true if the monad contains `exc/failure`
  or if `exc/success` wraps value satisfying PRED predicate."
  [pred]
  `(fn [*val#]
     (and (exc/exception? *val#)
          (if (exc/success? *val#)
            (m/bind *val# ~pred)
            true))))

(defn-spec fp->*age (exception-of? pos-int?)
  [path file?]
...)

I found it useful in two ways:

  1. it makes sure that the function returns proper value wrapped in the proper context.
  2. It's a good alternative to documenting functions via name suffixes like fp->*age-try-m.

At the same time, it's not like using monads in Clojure is an idiomatic thing to do. But I'm pretty sure that someone can find a ton more use cases like this.

Mb README should mention it? Or it's too non-idiomatic/narrow/self-evident?


Disclaimer: I'm a Clojure n00b so mb it's all some kind of terrible heresy 😃

jeaye commented

Thanks for the suggestion! I'm trying to keep Orchestra as single-purposed as possible, so I won't be adding this to the readme. I am very happy that it's synergizing well with your other deps though. :)