Public Vars

Back

when-some (clj)

(source)

macro

(when-some bindings & body)
bindings => binding-form test When test is not nil, evaluates body with binding-form bound to the value of test

Examples

typedclojure/typedclojure
(ns typed.clojure.jvm
  "JVM-specific annotations and operations.
  See typed.clojure for cross-platform ops."
  (:require clojure.core.typed
            [clojure.core.typed.current-impl :as impl]
            [clojure.core.typed.internal :refer [take-when]]
            [typed.cljc.runtime.env-utils :refer [delay-type]]
            [clojure.core.typed.macros :as macros]))

(defmacro override-class [& args]
  (let [[binder args] (take-when vector? args)
        [nme args] (take-when symbol? args)
        _ (assert (symbol? nme) (str "Missing name in override-class" [nme args]))
        [opts args] (take-when map? args)
        opts (if opts
               (do (assert (empty? args) (str "Trailing args to override-class: " (pr-str args)))
                   opts)
               (apply hash-map args))
        this-ns (ns-name *ns*)]
    `(clojure.core.typed/tc-ignore
       (let [nme# (or (when-some [^Class c# (ns-resolve '~this-ns '~nme)]
                        (when (class? c#)
                          (-> c# .getName symbol)))
                      (throw (ex-info (str "Could not resolve class: " '~nme) {:class-name '~nme})))]
          ;; TODO runtime env
         #_
         (impl/add-rclass-env nme# {:op :RClass})
         ;; type env
         ;inline when-bindable-defining-ns
         (macros/when-bindable-defining-ns '~this-ns
           (impl/with-clojure-impl
             (impl/add-rclass nme# (delay-type
                                     ((requiring-resolve 'typed.clj.checker.parse-unparse/with-parse-ns*)
                                      '~this-ns
                                      #((requiring-resolve 'typed.cljc.checker.base-env-helper/make-RClass)
                                        nme#
                                        '~binder
                                        '~opts))))))))))
RutledgePaulV/piped
(ns piped.utils-test
  (:require [piped.utils :refer :all]
            [clojure.core.async :as async]
            [clojure.test :refer :all]))

    (async/go-loop []
      (when-some [batch (async/<! return)]
        (swap! received conj batch)
        (recur)))

    (async/go-loop []
      (when-some [item (async/<! return)]
        (swap! received conj item)
        (recur)))
metosin/clojure-bootcamp
(ns twitter-sphere.play-ground
  (:require [clojure.core.async
                :as async
                :refer [chan go >!! >! <!! <!
                        alt! alts! alt!! alts!!]]))

(go
  (loop []
    (when-some [v (<! source)]
      (>! target (inc v))
      (recur))))

(go
  (loop []
    (when-some [v (<! target)]
       (println "got:" v)
       (recur))))