Public Vars

Back

iteration (clj)

(source)

function

(iteration step & {:keys [somef vf kf initk], :or {vf identity, kf identity, somef some?, initk nil}})
Creates a seqable/reducible via repeated calls to step, a function of some (continuation token) 'k'. The first call to step will be passed initk, returning 'ret'. Iff (somef ret) is true, (vf ret) will be included in the iteration, else iteration will terminate and vf/kf will not be called. If (kf ret) is non-nil it will be passed to the next step call, else iteration will terminate. This can be used e.g. to consume APIs that return paginated or batched data. step - (possibly impure) fn of 'k' -> 'ret' :somef - fn of 'ret' -> logical true/false, default 'some?' :vf - fn of 'ret' -> 'v', a value produced by the iteration, default 'identity' :kf - fn of 'ret' -> 'next-k' or nil (signaling 'do not continue'), default 'identity' :initk - the first value passed to step, default 'nil' It is presumed that step with non-initk is unreproducible/non-idempotent. If step with initk is unreproducible it is on the consumer to not consume twice.

Examples

compdemocracy/polis
(ns pca-test
  (:use test-helpers)
  (:require [clojure.test :refer :all]
            [polismath.math.named-matrix :refer :all]
            [clojure.math.numeric-tower :refer :all]
            [clojure.core.matrix :as m]
            [polismath.math.pca :refer :all]))


(deftest powerit
  (testing "Should generally work"
    (let [data (m/matrix [[ 1 0  0]
                          [-1 1  0.1]
                          [ 0 1  0.1]
                          [ 0 1 -0.1]])
          expected [-0.34217 0.93906 0.032633]
          pc-from-start (fn [start] (power-iteration data 2 start))]
hraberg/deuce
(ns deuce.emacs.macros
  (:use [deuce.emacs-lisp :only (defun defvar)])
  (:require [clojure.core :as c])
  (:refer-clojure :exclude []))

  Optional third arg LOOPFUNC may be a function that is called prior to
  each iteration of the macro.  Iteration stops if LOOPFUNC returns nil."
  )

  In Lisp, optional second arg LOOPFUNC may be a function that is called prior to
  each iteration of the macro.  Iteration stops if LOOPFUNC returns nil."
  (interactive "p"))

  In Lisp, optional second arg LOOPFUNC may be a function that is called prior to
  each iteration of the macro.  Iteration stops if LOOPFUNC returns nil."
  (interactive "p"))
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/iteration (t/All [k v ret] [[k :-> ret] & :optional {:somef [ret :-> t/Any]
                                                        :vf [ret :-> v]
                                                        :kf [ret :-> k]
                                                        :initk k}
                               :-> (t/Seqable ret)])
babashka/sci.configs
(ns sci.configs.clojure-1-11
  (:require [sci.core :as sci]
            [sci.impl.utils :refer [clojure-core-ns]]
            [clojure.core :as c]))

(def ^:private clojure-core-namespace-extras-1-11
  {'abs (sci/copy-var c/abs clojure-core-ns)
   'NaN? (sci/copy-var c/NaN? clojure-core-ns)
   'infinite? (sci/copy-var c/infinite? clojure-core-ns)
   'parse-double (sci/copy-var c/parse-double clojure-core-ns)
   'parse-long (sci/copy-var c/parse-long clojure-core-ns)
   'parse-boolean (sci/copy-var c/parse-boolean clojure-core-ns)
   'parse-uuid (sci/copy-var c/parse-uuid clojure-core-ns)
   'random-uuid (sci/copy-var c/random-uuid clojure-core-ns)
   'update-keys (sci/copy-var c/update-keys clojure-core-ns)
   'update-vals (sci/copy-var c/update-vals clojure-core-ns)
   'iteration (sci/copy-var c/iteration clojure-core-ns)})
PacktPublishing/Clojure-Programming-Cookbook
(ns performance-example.criterium-example
    (:require [criterium.core :refer
             [bench with-progress-reporting report-result quick-bench benchmark quick-benchmark]]
            [clojure.core.reducers :as r]
            [criterium.stats :as stats]
            ))

(with-progress-reporting
  (bench (Thread/sleep 1000) :verbose))
;;=> Estimating sampling overhead
;;=> Warming up for JIT optimisations 10000000000 ...
;;=>   compilation occurred before 275187 iterations
;;=>   compilation occurred before 35488371 iterations
;;=>   compilation occurred before 69326040 iterations
;;=>   compilation occurred before 70151349 iterations
;;=>   compilation occurred before 105364533 iterations
;;=>   compilation occurred before 140577717 iterations
;;=> Estimating execution count ...
;;=> Sampling ...
;;=> Final GC...
;;=> Checking GC...
;;=> Finding outliers ...
;;=> Bootstrapping ...
;;=> Checking outlier significance
;;=> Warming up for JIT optimisations 10000000000 ...
;;=>   compilation occurred before 1 iterations
;;=> Estimating execution count ...
;;=> Sampling ...
;;=> Final GC...
;;=> Checking GC...
;;=> Finding outliers ...
;;=> Bootstrapping ...
;;=> Checking outlier significance
;;=> amd64 Linux 3.16.0-38-generic 4 cpu(s)
;;=> Java HotSpot(TM) 64-Bit Server VM 25.65-b01
;;=> Runtime arguments: -Dfile.encoding=UTF-8 -XX:+TieredCompilation -XX:TieredStopAtLevel=1 -XX:-Omit;;=> StackTraceInFastThrow -Dclojure.compile.path=/home/makoto/clojure/clojure-packt-book/chapter09/cr;;=> iterium-example/target/classes -Dcriterium-example.version=0.1.0-SNAPSHOT -Dclojure.debug=false
;;=> Evaluation count : 780 in 60 samples of 13 calls.
;;=>       Execution time sample mean : 77.498879 ms
;;=>              Execution time mean : 77.517145 ms
;;=> Execution time sample std-deviation : 1.418071 ms
;;=>     Execution time std-deviation : 1.441261 ms
;;=>    Execution time lower quantile : 76.678226 ms ( 2.5%)
;;=>    Execution time upper quantile : 82.447959 ms (97.5%)
;;=>                    Overhead used : 9.491795 ns
;;=> 
;;=> Found 6 outliers in 60 samples (10.0000 %)
;;=>     low-severe     1 (1.6667 %)
;;=>     low-mild     5 (8.3333 %)
;;=>  Variance from outliers : 7.8102 % Variance is slightly inflated by outliers