Public Vars

Back

condp (clj)

(source)

macro

(condp pred expr & clauses)
Takes a binary predicate, an expression, and a set of clauses. Each clause can take the form of either: test-expr result-expr test-expr :>> result-fn Note :>> is an ordinary keyword. For each clause, (pred test-expr expr) is evaluated. If it returns logical true, the clause is a match. If a binary clause matches, the result-expr is returned, if a ternary clause matches, its result-fn, which must be a unary function, is called with the result of the predicate as its argument, the result of that call being the return value of condp. A single default expression can follow the clauses, and its value will be returned if no clause matches. If no default expression is provided and no clause matches, an IllegalArgumentException is thrown.

Examples

metabase/metabase
(ns metabase.async.util-test
  (:require
   [clojure.core.async :as a]
   [clojure.test :refer :all]
   [metabase.async.util :as async.u]
   [metabase.test.util.async :as tu.async]))

  (testing "if you are a knucklehead and write directly to out-chan it should close `in-chan`"
    (tu.async/with-open-channels [in-chan  (a/promise-chan)
                                  out-chan (a/promise-chan)]
      (async.u/promise-pipe in-chan out-chan)
      (a/>!! out-chan "Oops")
      (let [timeout-chan (a/timeout 1000)
            [val port]   (a/alts!! [in-chan timeout-chan])]
        (is (= nil
               val))
        (is (= :in-chan
               (condp = port
                 in-chan      :in-chan
                 out-chan     :out-chan
                 timeout-chan :timeout-chan
                 port))))))
hraberg/deuce
(ns deuce.emacs.print
  (:use [deuce.emacs-lisp :only (defun defvar)])
  (:require [clojure.core :as c]
            [clojure.string :as s]
            [deuce.emacs.buffer :as buffer]
            [deuce.emacs.data :as data]
            [deuce.emacs.editfns :as editfns]
            [deuce.emacs.fns :as fns])
  (:refer-clojure :exclude [print]))

  If PRINTCHARFUN is omitted, the value of `standard-output' (which see)
  is used instead."
  (let [printcharfun (or printcharfun (data/symbol-value 'standard-output))
        s (prin1-to-string object)]
    (condp some [printcharfun]
      #{nil true} (editfns/message s)
      data/bufferp (binding [buffer/*current-buffer* printcharfun]
                     (editfns/insert s)))))
cloverage/cloverage
                  :incanter-bayes
                  {:ns-source
                   '(ns ^{:doc "This is library provides functions for performing
                basic Bayesian modeling and inference.
                "
                          :author "David Edgar Liebke"}
                     incanter.bayes
                      (:use [incanter.core :only (matrix mmult mult div minus trans ncol nrow
                                                         plus to-list decomp-cholesky solve half-vectorize
                                                         vectorize symmetric-matrix identity-matrix kronecker
                                                         bind-columns)]
                            [incanter.stats :only (sample-normal sample-gamma sample-dirichlet
                                                                 sample-inv-wishart sample-mvn mean)]))
                   :expected '#{incanter.core incanter.stats}}
                  :parkour-dseq
                  {:ns-source
                   '(ns parkour.io.dseq
                      (:require [clojure.core.protocols :as ccp]
                                [clojure.core.reducers :as r]
                                [parkour (conf :as conf) (cstep :as cstep) (wrapper :as w)]
                                [parkour.mapreduce (source :as src)]
                                [parkour.io.dseq (mapred :as mr1) (mapreduce :as mr2)]
                                [parkour.util :refer [ignore-errors]])
                      (:import [java.io Closeable Writer]
                               [clojure.lang IObj]))
                   :expected '#{clojure.core.protocols clojure.core.reducers parkour.conf
                                parkour.cstep parkour.wrapper parkour.mapreduce.source
                                parkour.io.dseq.mapred parkour.io.dseq.mapreduce
                                parkour.util}}})

(t/deftest cyclic-dependency-test
  (t/testing "Should throw an Exception if cyclic dependencies exist between namespaces"
    (with-redefs [source/ns-form (fn [ns-symbol]
                                   (condp = ns-symbol
                                     'a '(ns a (:require b c))
                                     'b '(ns b (:require c))
                                     'c '(ns c (:require a))))]
      (t/is (thrown-with-msg?
             clojure.lang.ExceptionInfo
             #"Circular dependency between c and a"
             (cd/in-dependency-order '[a b c]))))))

(t/deftest isolated-namespace-test
  (t/testing "Isolated namespaces should be included in the result"
    (with-redefs [source/ns-form (fn [ns-symbol]
                                   (condp = ns-symbol
                                     'a '(ns a)
                                     'b '(ns b)
                                     'c '(ns c (:require b))))]
      (t/is (= '[b c a] (cd/in-dependency-order '[a b c]))))))
yetanalytics/dave
(ns com.yetanalytics.dave.ui.app.workbook.data
  (:require [re-frame.core :as re-frame]
            [com.yetanalytics.dave.workbook.data :as data]
            [com.yetanalytics.dave.workbook.data.state :as state]
            [com.yetanalytics.dave.workbook.data.lrs.client
             :as lrs-client]
            [clojure.core.async :as a :include-macros true]
            [clojure.spec.alpha :as s]
            [goog.string :refer [format]]
            [goog.string.format]))

(re-frame/reg-event-fx
 ::create-lrs
 (fn [{:keys [db] :as ctx}
      [_
       workbook-id
       lrs-data-spec
       ?check-resp]]
   (if-let [{:keys [success status] :as resp} ?check-resp]
     (if success
       ;; TODO: proceed with creation
       {:notify/snackbar
        {:message "Connecting LRS..."}
        :dispatch-n [[::change
                      workbook-id
                      lrs-data-spec]
                     [:dialog/dismiss]]}
       {:notify/snackbar
        {:message
         (format "LRS Error: %d"
                 status)
         #_(condp contains? status
           #{401 403} "Invalid Credentials"
           #{404} "Invalid Endpoint"
           (str ))}}
       )
     (if (s/valid? data/data-spec lrs-data-spec)
       {:dispatch [::check-lrs
                   lrs-data-spec
                   [::create-lrs
                    workbook-id
                    lrs-data-spec]]}
       {:notify/snackbar
        {:message "Invalid LRS Info!"}}))))