CrossClj

2.96.0 docs

SourceDocs



RECENT
    VARS
    ->?singleton
    ->body-in-map
    ->Swapped
    ->vec
    abs
    as-?bool
    as-?email
    as-?float
    as-?int
    as-?kw
    as-?name
    as-?nblank
    as-?nemail
    as-bool
    as-float
    as-int
    as-map
    assert-min-encore-version
    assertion-error
    assoc-conj
    assoc-some
    assoc-when
    atom?
    ba-concat
    ba-split
    ba=
    backport-run!
    bench
    bench*
    bytes-class
    bytes?
    case-eval
    catch-errors
    caught-error-data
    chan?
    check-all
    check-some
    clamp
    clamp*
    clj1098
    compile-if
    cond!
    cond-throw
    conj-some
    contains-in?
    count-words
    declare-remote
    defalias
    defonce*
    dissoc-in
    distinct-by
    distinct-elements?
    distinctv
    doto-cond
    encore-version
    error-data
    error?
    exception?
    exp-backoff
    explode-keyword
    file-resources-modified?
    filter-keys
    filter-kvs
    filter-vals
    format
    format*
    format-query-string
    fq-name
    fzipmap
    gc-now?
    gc-rate
    get-file-resource-?last-modified
    greatest
    have
    have!
    have!?
    have-in
    have-in!
    have?
    hcond
    hpred
    hthrow
    if-cljs
    if-lets
    interleave-all
    into-all
    join-once
    keys<=
    keys=
    keys=nnil?
    keys>=
    keywordize-map
    ks-nnil?
    ks<=
    ks=
    ks>=
    kw-identical?
    least
    logging-level
    map->Swapped
    map-keys
    map-kvs
    map-vals
    mapply
    max*
    memoize*
    memoize-1
    memoize1
    memoize_
    memoized
    merge-deep
    merge-deep-with
    merge-headers
    merge-keywords
    merge-url-with-query-string
    min*
    ms
    ms->secs
    name-with-attrs
    nano-time
    nblank-str?
    nblank?
    nested-merge
    nested-merge-with
    nil->str
    nneg-int?
    nneg-num?
    nneg?
    nnil-set
    nnil=
    nnil?
    non-throwing
    norm-word-breaks
    normalize-headers
    now-dt
    now-udt
    now-udt-mock-fn
    nvec?
    parse-bool
    parse-float
    parse-int
    parse-query-params
    path
    pos-int?
    pos-num?
    pow
    pr-edn
    qb
    qbench
    queue
    queue*
    queue?
    quick-bench
    rate-limit
    rate-limited
    rate-limiter
    rate-limiter*
    rcompare
    re-pattern?
    read-edn
    read-edn-str
    redirect-resp
    remove-vals
    removev
    repeatedly*
    repeatedly-into
    repeatedly-into*
    replace-in
    replace-in*
    reset-in!
    round
    round*
    round1
    round2
    rsome
    secs
    secs->ms
    seq-kvs
    session-swap
    set*
    set-body
    set-status
    simple-date-format
    simple-date-format*
    singleton?
    slurp-file-resource
    slurp-resource
    spaced-str
    spaced-str-with-nils
    str-?index
    str-contains?
    str-ends-with?
    str-replace
    str-starts-with?
    stringy?
    sub-indexes
    substr
    subvec*
    swap-in!
    swap-val!
    swapped
    swapped*
    swapped*-in
    swapped?
    takev
    thread-local-proxy
    throwable?
    time-ms
    time-ns
    translate-signed-idx
    udt?
    update-in*
    url-decode
    url-encode
    uuid-str
    vec*
    vec2?
    vec3?
    vsplit-first
    vsplit-last
    when-lets
    xdistinct
    zero-num?

    « Index of all namespaces of this project

    Some tools I use often, w/o any external deps.
    

    — Peter Taoussanis

    (->?singleton coll)
    Private
    (->body-in-map x)
    (->Swapped new-val return-val)
    Positional factory function for class taoensso.encore.Swapped.
    
    (as-?email ?s)
    (as-?nemail ?s)
    (as-map kvs & [kf vf])
    Cross between hash-map & map-kvs.
    
    (assert-min-encore-version min-version)
    (assertion-error msg)
    Private
    (assoc-conj m k v)
    (assoc-some m & kvs)
    Assocs each kv iff its value is not nil.
    
    (assoc-when m & kvs)
    Assocs each kv iff its val is truthy.
    
    (ba-concat ba1 ba2)
    (ba-split ba idx)
    (backport-run! proc coll)
    run! from Clojure 1.7+
    
    macro
    (bench nlaps bench*-opts & body)
    (bench* nlaps {:keys [nlaps-warmup nthreads as-ns?], :or {nlaps-warmup 0, nthreads 1}} f)
    Repeatedly executes fn and returns time taken to complete execution.
    
    macro
    (case-eval e & clauses)
    Like case but evaluates test constants for their compile-time value.
    
    macro
    (catch-errors & body)
    Experimental. Returns [<?result> <?error>].
    
    macro
    (caught-error-data & body)
    Handy for error-throwing unit tests.
    
    macro
    (check-all test)(check-all test & more)
    Experimental. Returns all logical false/throwing expressions (ids/forms), or nil.
    
    macro
    (check-some test & more)(check-some test)
    Experimental. Returns first logical false/throwing expression (id/form), or nil.
    
    (clamp nmin nmax n)
    macro
    (clamp* nmin nmax n)
    (clj1098 x)
    Workaround for Clojure versions [1.4, 1.5) that blow up on reduce-kvs
    against a nil coll, Ref. http://dev.clojure.org/jira/browse/CLJ-1098.
    macro
    (compile-if test then & [?else])
    Evaluates test. If it doesn't error and returns logical true, expands to
    then, otherwise expands to else. Stolen from clojure.core.reducers.
    (compile-if (Class/forName "java.util.concurrent.ForkJoinTask")
      (do-cool-stuff-with-fork-join)
      (fall-back-to-executor-services))
    macro
    (cond! & clauses)
    Like cond but throws on no-match like case, condp.
    
    macro
    (cond-throw & args)
    (conj-some)(conj-some coll)(conj-some coll ?x)(conj-some coll ?x & ?xs)
    (contains-in? coll ks)
    macro
    (declare-remote & names)
    Declares the given ns-qualified names, preserving symbol metadata. Useful for
    circular dependencies.
    macro
    (defalias target)(defalias name target)(defalias name target doc)
    Defines an alias for a var, preserving metadata. Adapted from
    clojure.contrib/def.clj, Ref. http://goo.gl/xpjeH
    macro
    (defonce* name expr)
    Like clojure.core/defonce but supports optional docstring and attributes
    map for name symbol.
    (dissoc-in m ks & dissoc-ks)
    (distinct-by keyfn coll)
    (distinct-elements? x)
    (distinctv coll)(distinctv keyfn coll)
    Prefer set when order doesn't matter (much faster).
    
    macro
    (doto-cond [name x] & clauses)
    Diabolical cross between doto, cond-> and as->.
    
    Used for lib-consumer version assertions
    
    (error-data x)
    Returns data map iff x is an error of any type on platform.
    
    (exp-backoff nattempt & [{:keys [factor], min' :min, max' :max, :or {factor 1000}}])
    Returns binary exponential backoff value.
    
    (explode-keyword k)
    Returns true iff any files backing the given named resources have changed
    since last call.
    (filter-keys pred m)
    (filter-kvs predk predv m)
    (filter-vals pred m)
    (format fmt & args)
    Like clojure.core/format but:
    * Returns "" when fmt is nil rather than throwing an NPE.
    * Formats nil as "nil" rather than "null".
    * Provides ClojureScript support via goog.string.format (this has fewer
      formatting options than Clojure's format!).
    (format* fmt args)
    (format-query-string m)
    (fq-name x)
    Like name but fully qualified: includes namespace in string when present.
    
    (fzipmap ks vs)
    Faster zipmap using transients.
    
    (get-file-resource-?last-modified rname)
    Returns last-modified time for file backing given named resource, or nil if
    file doesn't exist.
    (greatest coll & [?comparator])
    macro
    (have (:!) x)(have (:!) pred (:in) x)(have (:!) pred (:in) x & more-xs)
    EXPERIMENTAL. Takes a pred and one or more xs. Tests pred against each x,
    trapping errors. If any pred test fails, throws a detailed error. Otherwise
    returns input x/xs for convenient inline-use/binding.
    
    Options:
      * By default throws AssertionErrors subject to *assert* value (useful
        for catching errors during dev). Use a :! first arg to instead throw
        RuntimeExceptions irrespective of *assert* value (useful for important
        conditions in production).
      * Use an :in arg after pred to treat x/xs as evaluated coll/colls.
      * See hpred for various convenient pred modifier forms.
    
    Provides a small, simple, deeply flexible alternative to heavier tools like
    core.typed, Prismatic/schema.
    
      (fn square    [x]    (let [x     (have integer? x)]   (* x x)))
      (fn mult      [x y]  (let [[x y] (have integer? x y)] (* x y)))
      (fn mult-many [& xs] (reduce * (have :! [:or integer? float?] :in xs)))
    macro
    (have! & args)
    macro
    (have!? & args)
    macro
    (have-in a1 & an)
    macro
    (have-in! & args)
    macro
    (have? (:!) x)(have? (:!) pred (:in) x)(have? (:!) pred (:in) x & more-xs)
    EXPERIMENTAL. Like have but returns true rather than input on success
    (convenient for use in :pre/:post conds).
    
    **NB** Be cautious using :! tests in :pre/:post conds since :pre/:post conds
    are themselves subject to *assert* val.
    
      (fn square  [x]   {:pre [(have? integer? x)]}   (* x x))
      (fn mult    [x y] {:pre [(have? integer? x y)]} (* x y))
    (hcond hard? ns-str line x_ x-form pred pred-form)
    Implementation detail.
    
    (hpred pred-form)
    Implementation detail.
    
    (hthrow hard? ns-str ?line form val & [?err])
    Implementation detail.
    
    macro
    (if-cljs then else)
    Executes then clause iff generating ClojureScript code.
    Useful for writing macros that can produce different Clj/Cljs code (this isn't
    something Cljx currently provides support for). Stolen from Prismatic code,
    Ref. http://goo.gl/DhhhSN, http://goo.gl/Bhdyna.
    macro
    (if-lets bindings then)(if-lets bindings then else)
    Like if-let but binds multiple values iff all tests are true.
    
    (interleave-all)(interleave-all c1)(interleave-all c1 c2)(interleave-all c1 c2 & colls)
    Greedy version of interleave, Ref. http://goo.gl/KvzqWb.
    
    (into-all to from)(into-all to from & more)
    Like into but supports multiple "from"s.
    
    (join-once separator & coll)
    Like clojure.string/join but ensures no double separators.
    
    (keys<= m ks)
    (keys= m ks)
    (keys=nnil? m ks)
    (keys>= m ks)
    (keywordize-map m)
    (ks-nnil? ks m)
    (ks<= ks m)
    (ks= ks m)
    (ks>= ks m)
    (least coll & [?comparator])
    (map->Swapped m__7585__auto__)
    Factory function for class taoensso.encore.Swapped, taking a map of keywords to field values.
    
    (map-keys f m)
    (map-kvs kf vf m)
    (map-vals f m)
    (mapply f & args)
    Like apply but assumes last arg is a map whose elements should be applied
    to f as an unpaired seq:
      (mapply (fn [x & {:keys [y z]}] (str x y z)) 1 {:y 2 :z 3})
        where fn will receive args as: `(1 :y 2 :z 3)`.
    macro
    (max* n1 n2)
    (memoize* f)(memoize* ttl-ms f)(memoize* cache-size ttl-ms f)
    Like clojure.core/memoize but:
    * Uses delays to prevent race conditions on writes.
    * Supports auto invalidation & gc with ttl-ms option.
    * Supports manual invalidation by prepending args with :mem/del or :mem/fresh.
    * Supports cache size limit & gc with cache-size option.
    (memoize1 f)
    Great for Reactjs render op caching on mobile devices, etc.
    
    (memoize_ f)
    As clojure.core/memoize but uses delays to avoid write races.
    
    (memoized cache f & args)
    Like `(memoize* f)` but takes an explicit cache atom (possibly nil)
    and immediately applies memoized f to given arguments.
    (merge-headers resp headers)
    (merge-keywords ks & [no-slash?])
    (merge-url-with-query-string url m)
    macro
    (min* n1 n2)
    (ms & {:as opts, :keys [years months weeks days hours mins secs msecs ms]})
    Returns number of milliseconds in period defined by given args.
    
    (name-with-attrs name macro-args)
    Handles optional docstrings & attr maps for a macro def's name.
    Stolen from clojure.tools.macro.
    (nested-merge-with f & maps)
    (nnil= x y)(nnil= x y & more)
    Private
    (non-throwing pred)
    (norm-word-breaks s)
    Converts all word breaks of any form and length (including line breaks of any
    form, tabs, spaces, etc.) to a single regular space.
    (normalize-headers req-or-resp)
    (now-udt-mock-fn & [mock-udts])
    Useful for testing.
    
    (parse-query-params s & [keywordize? encoding])
    Based on ring-codec/form-decode.
    
    (path & parts)
    Joins string paths (URLs, file paths, etc.) ensuring correct "/"
    interposition.
    (pow n exp)
    (pr-edn x)(pr-edn opts x)
    macro
    (qb & args)
    macro
    (qbench & args)
    (queue)(queue coll)
    Returns a PersistentQueue.
    
    (queue* & items)
    macro
    (quick-bench nlaps form & more)(quick-bench nlaps form)
    Returns fastest of 3 sets of times for each form, in msecs.
    
    (rate-limit specs f)
    (rate-limited ncalls-limit window-ms f)
    (rate-limiter ncalls-limit window-ms)
    (rate-limiter* specs)
    Takes one or more rate specs of form [ncalls-limit window-ms ?spec-id] and
    returns a (fn [& [req-id])) that returns nil (=> all rate limits passed), or
    [<ms-wait> <worst-offending-spec-id>] / <ms-wait>.
    (rcompare x y)
    Reverse comparator.
    
    (read-edn-str opts s)(read-edn-str s)
    (redirect-resp url)(redirect-resp type url & [flash])
    (remove-vals pred m)
    Smaller, common-case version of filter-vals. Esp useful with nil?`/`blank?
    pred when constructing maps: {:foo (when _ <...>) :bar (when _ <...>)} in a
    way that preservers :or semantics.
    (removev pred coll)
    macro
    (repeatedly* n & body)
    (repeatedly-into coll n f)
    Like repeatedly but faster and conjs items into given collection.
    
    macro
    (repeatedly-into* coll n & body)
    (replace-in m & ops)
    Experimental. For use with swap!, etc.
    
    Private
    (replace-in* ?vf-type m ops)
    Reduces input with
    [<type> <ks> <reset-val-or-swap-fn>] or
           [<ks> <reset-val-or-swap-fn>] ops.
    (reset-in! atom_ ks new-val)(reset-in! atom_ ks new-val & more)
    Is to reset! as swap-in! is to swap!.
    
    (round n & [type nplaces])
    (round* n)(round* type n)(round* type nplaces n)
    (round1 n)
    Optimized common case.
    
    (round2 n)
    Optimized common case.
    
    (rsome pred coll)
    Faster some based on reduce.
    
    (secs->ms secs)
    (seq     {:a :A}) => ([:a :A])
    (seq-kvs {:a :A}) => (:a :A)
    (session-swap req resp f & args)
    Small util to help correctly manage (modify) funtional sessions. Please use
    this when writing Ring middleware! It's *so* easy to get this wrong and end up
    with subtle, tough-to-diagnose issues.
    (set-body resp body)
    (set-status resp code)
    (simple-date-format pattern & [{:keys [locale timezone], :as opts}])
    Returns a thread-local java.text.SimpleDateFormat for simple date formatting
    and parsing. Uses JVM's default locale + timezone when unspecified.
    
    (.format (simple-date-format "yyyy-MMM-dd") (Date.)) => "2014-Mar-07"
    Ref. http://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html
    
    Prefer the java.time (Java 8) or Joda-Time (external lib) APIs when available.
    Tower also offers facilities built on DateFormat (rather than the more
    restrictive SimpleDateFormat).
    Private
    Returns a SimpleDateFormat ThreadLocal proxy.
    
    (singleton? coll)
    Like slurp-resource but caches slurps against file's last-modified udt.
    
    (slurp-resource rname)
    Returns slurped named resource on classpath, or nil when resource not found.
    
    (spaced-str xs)
    (spaced-str-with-nils xs)
    (str-?index s substr & [start-idx last?])
    (str-contains? s substr)
    (str-ends-with? s substr)
    (str-replace s match replacement)
    Workaround for http://dev.clojure.org/jira/browse/CLJS-794,
    http://dev.clojure.org/jira/browse/CLJS-911.
    (str-starts-with? s substr)
    (sub-indexes x start-idx & {:keys [max-len end-idx]})
    Returns [<inclusive-start-idx*> <exclusive-end-idx*>] for counted 0-indexed
    input (str, vec, etc.) with support for:
      * Clamping of indexes beyond limits.
      * Max-length -> end-index.
      * -ive indexes (as +ive indexes but work from back of input):
        (+0) (+1) (+2) (+3) (+4)  ; inclusive +ive indexes
          h    e    l    l    o   ; 5 count
        (-5) (-4) (-3) (-2) (-1)  ; inclusive -ive indexes
    (substr s start-idx & [?max-len])
    Gives a consistent, flexible, cross-platform substring API built on
    sub-indexes.
    (subvec* v start-idx & [?max-len])
    Like subvec but uses sub-indexes.
    
    (swap-in! atom_ ks f)(swap-in! atom_ ks f & more)
    More powerful version of swap!:
    * Supports optional update-in semantics.
    * Swap fn can return `(swapped <new-val> <return-val>)` rather than just
      <new-val>. This is useful when writing atomic pull fns, etc.
    (swap-val! atom_ k f)
    Swaps associative value at key and returns the new value.
    Specialized, fast swap-in! for use mostly by memoization utils.
    (swapped new-val return-val)
    Private
    (swapped*-in m ks f)
    [<new-val> <return-val>]
    
    (takev n coll)
    macro
    (thread-local-proxy & body)
    Thread-safe proxy wrapper, Ref. http://goo.gl/CEBJnQ (instant.clj).
    
    macro
    (time-ms & body)
    Returns number of milliseconds it takes to execute body.
    
    macro
    (time-ns & body)
    Returns number of nanoseconds it takes to execute body.
    
    Private
    (translate-signed-idx signed-idx max-idx)
    (update-in* m ks f)
    Like update-in but faster, more flexible, and simpler (less ambiguous).
    
    (url-decode s & [encoding])
    Stolen from http://goo.gl/99NSR1.
    
    (url-encode s & [encoding])
    Stolen from http://goo.gl/99NSR1.
    
    (uuid-str max-length)(uuid-str)
    Returns a UUIDv4 string of form "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx",
    Ref. http://www.ietf.org/rfc/rfc4122.txt,
         https://gist.github.com/franks42/4159427
    (vsplit-first v)
    macro
    (when-lets bindings & body)
    Like when-let but binds multiple values iff all tests are true.
    
    (xdistinct)(xdistinct keyfn)