Why don't when-let and if-let support multiple bindings by default?

前端 未结 3 523
悲&欢浪女
悲&欢浪女 2020-12-29 23:54

Why don\'t when-let and if-let support multiple bindings by default?

So:

(when-let [a ...
           b ...]
  (+ a b))
         


        
3条回答
  •  清酒与你
    2020-12-30 00:15

    If you use cats, then there is a mlet function that you might find useful :

    (use 'cats.builtin)
    (require '[cats.core :as m])
    (require '[cats.monad.maybe :as maybe])
    
    (m/mlet [x (maybe/just 42)
             y nil]
      (m/return (+ x y)))
    ;; => nil
    

    As you can see, the mlet short-circuits when encountering a nil value.

    (from section 6.5.1 nil)

提交回复
热议问题