failjure icon indicating copy to clipboard operation
failjure copied to clipboard

Feature request: `when-ok` macro

Open alexanderjamesking opened this issue 3 years ago • 2 comments

For the occasions when you only care that the form passes and do not need a value from it, I find myself using when-let-ok?:

(f/when-let-ok? [_ (some-fn-that-returns-a-failure-or-a-value...)]
  ::woohoo)

I propose to add the macro when-ok:

(defmacro when-ok [form & body]
  (when-let-ok? [_# ~form]
    ~@body))

So we can write:

(f/when-ok (some-fn-that-returns-a-failure-or-a-value...)
  ::woohoo)

Happy to do a PR for this with tests if you're interested in adding it.

ps. Great library by the way, thank you for your efforts!

alexanderjamesking avatar Nov 16 '21 09:11 alexanderjamesking

Isn't it just combination of when and f/ok??

(when (f/ok? (some-fn-that-returns-a-failure-or-a-value))
  ::woohoo)

ACiep avatar Nov 17 '21 18:11 ACiep

Not exactly, (when (f/ok? ... returns nil on a failure whereas I'd like to return the failure.

alexanderjamesking avatar Nov 17 '21 18:11 alexanderjamesking