Public Vars

Back

partition-all (clj)

(source)

function

(partition-all n) (partition-all n coll) (partition-all n step coll)
Returns a lazy sequence of lists like partition, but may include partitions with fewer than n items at the end. Returns a stateful transducer when no collection is provided.

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-classes [& args]
  (assert (even? (count args)))
  `(do ~@(map (fn [[nme [frees & {:as opts}]]]
                `(override-class ~@(some-> (not-empty frees) vector) ~nme ~(or (not-empty opts) {})))
              (partition-all 2 args))))
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/partition-all (t/All [x] (t/IFn [t/Int :-> (t/Transducer x (t/NonEmptyAVec x))]
                                   [t/Int (t/? t/Int) (t/Seqable x) :-> (t/ASeq (t/NonEmptyASeq 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-partition-all
  (are [input-size part-size step] (= (->> (range input-size)
                                           (partition-all part-size step))
                                      (->> (range input-size)
                                           (rx/seq->o)
                                           (rx/partition-all part-size step)
                                           (rx/map #(rx/into [] %))
                                           (rx/concat*)
                                           (b/into [])))
       0 1 1
       10 2 2
       10 3 2
       15 30 4)

  (are [input-size part-size] (= (->> (range input-size)
                                      (partition-all part-size))
                                 (->> (range input-size)
                                      (rx/seq->o)
                                      (rx/partition-all part-size)
                                      (rx/map #(rx/into [] %))
                                      (rx/concat*)
                                      (b/into [])))
       0 1
       10 2
       10 3
       15 30))
halgari/naiad
(ns naiad.core-test
  (:require [clojure.test :refer :all]
            [clojure.core.async :as async]
            [naiad :as df :refer [flow-result]]))

  (testing "partition"
    (is (= (flow-result
             (df/partition-all 2 [1 2 3 4]))
          [[1 2] [3 4]]))
rill-event-sourcing/rill
(ns rill.event-channel-test
  (:require [rill.event-channel :refer [event-channel]]
            [clojure.test :refer [is deftest testing]]
            [rill.temp-store :refer [given]]
            [rill.event-store :as store]
            [rill.event-stream :refer [any-stream-version empty-stream-version]]
            [rill.message :as message]
            [clojure.core.async :as async :refer [<! <!! go close!]]
            [rill.uuid :refer [new-id]]
            [schema.core :as s]))

(deftest event-channel-test
  (let [store (given [])]
    (let [channel (event-channel store stream-id empty-stream-version 10)]
      (async/thread
        (doseq [chunk (partition-all 10 events)]
          (is (store/append-events store stream-id any-stream-version chunk))
          (Thread/sleep 50)))
      (is (= (<!! (go
                    (doseq [e events]
                      (let [e' (loop [e' (<! channel)]
                                 (if (= :rill.event-channel/CaughtUp (message/type e'))
                                   (recur (<! channel))
                                   e'))]
                        (is (= e' e))))
                    (close! channel)
                    :done))
             :done)))))