CrossClj

0.2.3 docs

SourceDocs



RECENT
    VARS
    *log-level*
    ->?singleton
    ->Swapped
    ->vec
    abs
    ajax-lite
    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?
    backport-run!
    chan?
    clamp
    clj1098
    coerce-xhr-params
    conj-some
    console-log
    contains-in?
    count-words
    debugf
    dissoc-in
    distinct-by
    distinct-elements?
    distinctv
    encore-version
    error-data
    error?
    errorf
    exp-backoff
    explode-keyword
    fatalf
    filter-keys
    filter-kvs
    filter-vals
    format
    format*
    format-query-string
    fq-name
    fzipmap
    gc-now?
    gc-rate
    get-pooled-xhr!
    get-window-location
    greatest
    hcond
    hpred
    hthrow
    infof
    interleave-all
    into-all
    join-once
    keys<=
    keys=
    keys=nnil?
    keys>=
    keywordize-map
    ks-nnil?
    ks<=
    ks=
    ks>=
    kw-identical?
    least
    log
    log?
    logf
    logging-level
    logp
    map->Swapped
    map-keys
    map-kvs
    map-vals
    mapply
    memoize*
    memoize-1
    memoize1
    memoize_
    memoized
    merge-deep
    merge-deep-with
    merge-keywords
    merge-url-with-query-string
    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
    now-dt
    now-udt
    now-udt-mock-fn
    nvec?
    oget
    parse-bool
    parse-float
    parse-int
    parse-query-params
    path
    pos-int?
    pos-num?
    pow
    pr-edn
    queue
    queue*
    queue?
    rate-limit
    rate-limited
    rate-limiter
    rate-limiter*
    rcompare
    re-pattern?
    read-edn
    read-edn-str
    remove-vals
    removev
    repeatedly-into
    replace-in
    replace-in*
    reportf
    reset-in!
    round
    round*
    round1
    round2
    rsome
    sayf
    sayp
    secs
    secs->ms
    seq-kvs
    set*
    set-exp-backoff-timeout!
    singleton?
    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*
    swapped*-in
    swapped?
    takev
    tracef
    translate-signed-idx
    udt?
    undefined->nil
    update-in*
    url-decode
    url-encode
    uuid-str
    vec*
    vec2?
    vec3?
    vsplit-first
    vsplit-last
    warnf
    xdistinct
    xhr-pool_
    zero-num?

    « Index of all namespaces of this project

    Some tools I use often, w/o any external deps.
    
    Dynamic
    DEPRECATED
    
    (->?singleton coll)
    (->Swapped new-val return-val)
    (ajax-lite uri {:keys [method params headers timeout-ms resp-type with-credentials? progress-fn errorf], :as opts, :or {method :get, timeout-ms 10000, resp-type :auto, errorf logf}} callback)
    Alpha - subject to change.
    Simple+lightweight Ajax via Google Closure. Returns nil, or the xhr instance.
    Ref. https://developers.google.com/closure/library/docs/xhrio.
    
    (ajax-lite "/my-post-route"
      {:method     :post
       :params     {:username "Rich Hickey"
                    :type     "Awesome"}
       :headers    {"Foo" "Bar"}
       :resp-type  :text
       :timeout-ms 7000
       :with-credentials? false ; Enable if using CORS (requires xhr v2+)
      }
      (fn async-callback [resp-map]
        (let [{:keys [success? ?status ?error ?content ?content-type]} resp-map]
          ;; ?status  - 200, 404, ..., or nil on no response
          ;; ?error   - e/o #{:xhr-pool-depleted :exception :http-error :abort
          ;;                  :timeout :no-content <http-error-status> nil}
          (js/alert (str "Ajax response: " resp-map)))))
    (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.
    
    (backport-run! proc coll)
    run! from Clojure 1.7+
    
    (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.
    Private
    (coerce-xhr-params uri method params)
    [uri method get-or-post-params] -> [uri post-content]
    
    (conj-some)(conj-some coll)(conj-some coll ?x)(conj-some coll ?x & ?xs)
    (contains-in? coll ks)
    (debugf fmt & xs)
    (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).
    
    Used for lib-consumer version assertions
    
    (error-data x)
    Returns data map iff x is an error of any type on platform.
    
    (errorf fmt & xs)
    (exp-backoff nattempt & [{:keys [factor], min' :min, max' :max, :or {factor 1000}}])
    Returns binary exponential backoff value.
    
    (explode-keyword k)
    (fatalf fmt & xs)
    (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.
    
    Private
    (get-pooled-xhr!)
    Returns an immediately available XhrIo instance, or nil. The instance must be
    released back to pool manually.
    (get-window-location)
    Returns browser window's current location. Forgeable.
    
    (greatest coll & [?comparator])
    (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.
    
    (infof fmt & xs)
    (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])
    (log & xs)
    (logf fmt & xs)
    (logp & xs)
    (map->Swapped G__27826)
    (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)`.
    (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-keywords ks & [no-slash?])
    (merge-url-with-query-string url m)
    (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.
    (now-udt-mock-fn & [mock-udts])
    Useful for testing.
    
    (oget o k)(oget o k1 k2)(oget o k1 k2 & ks)
    Like aget for JS objects, Ref. https://goo.gl/eze8hY. Unlike aget,
    returns nil for missing keys instead of throwing.
    (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)
    (queue)(queue coll)
    Returns a PersistentQueue.
    
    (queue* & items)
    (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 s)
    (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)
    (repeatedly-into coll n f)
    Like repeatedly but faster and conjs items into given collection.
    
    (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.
    (reportf fmt & xs)
    (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.
    
    (sayf fmt & xs)
    (sayp & xs)
    (secs->ms secs)
    (seq     {:a :A}) => ([:a :A])
    (seq-kvs {:a :A}) => (:a :A)
    (set-exp-backoff-timeout! nullary-f & [nattempt])
    (singleton? coll)
    (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)
    (tracef fmt & xs)
    Private
    (translate-signed-idx signed-idx max-idx)
    (undefined->nil x)
    (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)
    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)
    (warnf fmt & xs)
    (xdistinct)(xdistinct keyfn)