Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: when-ok macro #30

Open
alexanderjamesking opened this issue Nov 16, 2021 · 2 comments
Open

Feature request: when-ok macro #30

alexanderjamesking opened this issue Nov 16, 2021 · 2 comments

Comments

@alexanderjamesking
Copy link

alexanderjamesking commented Nov 16, 2021

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!

@ACiep
Copy link

ACiep commented Nov 17, 2021

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

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

@alexanderjamesking
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants