Public Vars

Back

take-while (clj)

(source)

function

(take-while pred) (take-while pred coll)
Returns a lazy sequence of successive items from coll while (pred item) returns logical true. pred must be free of side-effects. Returns a transducer when no collection is provided.

Examples

Netflix/PigPen
(ns pigpen.rx.extensions-test
  (:use clojure.test
        pigpen.rx.extensions)
  (:require [rx.lang.clojure.core :as rx]
            [rx.lang.clojure.blocking :as rx-block])
  (:import [rx Observable Observer Subscriber Subscription]
           [rx.observables BlockingObservable]))

                 (let [cancel (atom false)]
                   (.add o
                         (reify Subscription
                           (unsubscribe [this]
                             (swap! cancel (constantly true)))))
                   (future
                     (doseq [i (take-while (fn [_] (not @cancel)) (range))]
                       (.onNext o i)
                       (swap! values #(conj % i))
                       (Thread/sleep 3))))))
        mo (multicast data)
typedclojure/typedclojure
(ns ^:no-doc typed.ann.clojure
  "Type annotations for the base Clojure distribution."
  #?(:cljs (:require-macros [typed.ann-macros.clojure :as macros]))
  (:require [clojure.core :as cc]
            [typed.clojure :as t]
            #?(:clj [typed.ann-macros.clojure :as macros])
            #?(:clj typed.ann.clojure.jvm) ;; jvm annotations
            #?(:clj clojure.core.typed))
  #?(:clj
     (:import (clojure.lang PersistentHashSet PersistentList
                            APersistentMap #_IPersistentCollection
                            #_ITransientSet
                            IRef)
              (java.util Comparator Collection))))


cc/take-while (t/All [x y] (t/IFn [[x :-> t/Any] :-> (t/Transducer x x)]
                                  [[x :-> t/Any] (t/Seqable x) :-> (t/ASeq x)]))
cc/drop-while (t/All [x] (t/IFn [[x :-> t/Any] :-> (t/Transducer x x)]
                                [[x :-> t/Any] (t/Seqable x) :-> (t/ASeq x)]))
ReactiveX/RxClojure
(ns rx.lang.clojure.core-test
  (:require [rx.lang.clojure.core :as rx]
            [rx.lang.clojure.blocking :as b]
            [rx.lang.clojure.future :as f]
            [clojure.test :refer [deftest is testing are]]))

(deftest test-take-while
  (is (= (into [] (take-while even? [2 4 6 8 1 2 3]))
         (b/into [] (rx/take-while even? (rx/seq->o [2 4 6 8 1 2 3]))))))
aliostad/deep-learning-lang-detection
(ns fluxion-test
  (:require [clojure.core.async :refer [chan <!! onto-chan]]
            [fluxion :refer :all]
            [clojure.test :refer :all]
            [clojure.set :as set]
            [clojure.data.generators :as gen]
            [clojure.test.generative :refer [defspec]]
            [clojure.test.generative.runner :as runner]))

;; Do too much math so that missing one beat doesn't mean each
;; subsequent beat is 100% error in the check.
(defspec timer-is-roughly-periodic
  (fn [interval beats]
    (let [t (timer interval)
          ticks (loop [ticks []
                       beats-to-go beats]
                  (if (< 0 beats-to-go)
                    (recur (conj ticks (<!! t))
                           (dec beats-to-go))
                    ticks))
          lt (last ticks)
          target-schedule (take-while #(<= % lt) (iterate (partial + interval) (first ticks)))]
      [ticks target-schedule]))
  [^{:tag (gen/uniform 80 120)} interval ^{:tag (gen/uniform 80 120)} beats]
  (let [ticks (first %)
        target-schedule (nth % 1)
        error (memoize (fn [target observed]
                         (Math/abs (- target observed))))
        errors (into {}
                     (map
                      (fn [[k v]]
                        [k (sort-by last v)])
                      (group-by first
                                (for [target target-schedule]
                                  (let [nearest-tick (apply min-key
                                                            (partial error target)
                                                            ticks)]
                                    [nearest-tick target (error target nearest-tick)])))))
        tick-errors (for [tick ticks]
                      (/ (or (last (first (errors tick)))
                             interval) interval))
        avg-error (/ (apply + tick-errors) (count tick-errors))
        picked-targets  (map #(nth (first %) 1) (vals errors))
        missed-targets (set/difference (set target-schedule)
                                       (set picked-targets))]
    (assert (<= avg-error 1/10) (str "Average error " 1/10 " greater than " 1/10))
    (assert (< (/ (count missed-targets) beats) 1/10)
            (str "Missed target points " (count missed-targets)
                 " greater than " (* 1/10 beats)))))
gixxi/lambdaroyal-memory
(ns 
    ^{:doc "(Performance) Unittests for lambdaroyal memory search abstraction that builds data projections."
      :author "christian.meichsner@live.com"}
    lambdaroyal.memory.abstraction.test-reverse-search-projection
  (:require [midje.sweet :refer :all]
            [lambdaroyal.memory.core.tx :refer :all]
            [lambdaroyal.memory.abstraction.search :as search]
            [lambdaroyal.memory.core.context :refer :all]
            [lambdaroyal.memory.helper :refer :all]
            [clojure.core.async :refer [>! alts!! timeout chan go]])
  (:import [java.text SimpleDateFormat]))

         (let [apple-line-items (take 2 (filter #(= (first apple) (-> % last :art1)) (select tx :line-item)))
               _ (doseq [x apple-line-items] (println x))
               banana-line-items (take 3 (filter #(= (first banana) (-> % last :art1)) (select tx :line-item)))
               _ (doseq [x banana-line-items] (println x))
               xs (concat banana-line-items apple-line-items)
               proj (search/by-referencees tx :line-item :article xs :verbose true)
               proj' (search/proj tx (search/filter-xs :line-item xs)
                           (search/<<< :article :verbose true))
               proj'' (search/proj tx (search/filter-xs :line-item xs)
                                  (search/<<< :article :foreign-key :art2 :verbose true))
               proj''' (search/proj tx (search/filter-xs :line-item xs)
                                  (search/<<< :article :foreign-key :art2 :verbose true)
                                  (search/>>> :stock :verbose true))
               proj'''' (search/proj tx (search/filter-xs :line-item xs)
                                  (search/<<< :article :foreign-key :art2 :verbose true)
                                  (search/>>> :stock :verbose true :reverse true))
               proj''''' (search/proj tx (search/filter-xs :line-item xs)
                           (search/<<< :article :verbose true :reverse true))
               expected (take-while #(= (first avocado) (-> % last :art)) (select tx :stock [:art] >= [(first avocado)]))
               _ (doseq [x proj''']
                   (println :xεproj''' x))
               _ (doseq [x proj'''']
                   (println :xεproj'''' x))
               _ (doseq [x expected]
                   (println :xεexpected x))]
           (fact "by-referenees returns distinct referenced cards of article master-data " proj => [banana apple])
           (fact "<<< returns distinct referenced cards of article master-data " proj' => [banana apple])
           (fact "<<< :reverse true returns distinct referenced cards of article master-data " proj''''' => [banana apple])
           (fact "<<< on alternative foreign-key returns distinct referenced cards of article master-data " proj'' => [banana apple avocado])
           (fact "<<< :article followed by >>> :stock reveals stock " proj''' => (sort-by first expected))
           (fact "<<< :article followed by >>> :stock :reverse true reveals reversed stock " proj'''' => (reverse (sort-by first expected)))))