Public Vars

Back

map (clj)

(source)

function

(map f) (map f coll) (map f c1 c2) (map f c1 c2 c3) (map f c1 c2 c3 & colls)
Returns a lazy sequence consisting of the result of applying f to the set of first items of each coll, followed by applying f to the set of second items in each coll, until any one of the colls is exhausted. Any remaining items in other colls are ignored. Function f should accept number-of-colls arguments. Returns a transducer when no collection is provided.

Examples

clojure
(ns clojure.test-clojure.reducers
  (:require [clojure.core.reducers :as r]
            [clojure.test.generative :refer (defspec)]
            [clojure.data.generators :as gen])
  (:use clojure.test))

(defequivtest test-map
  [map r/map #(into [] %)]
  [inc dec #(Math/sqrt (Math/abs %))])

(defequivtest test-mapcat
  [mapcat r/mapcat #(into [] %)]
  [(fn [x] [x])
   (fn [x] [x (inc x)])
   (fn [x] [x (inc x) x])])

(deftest test-mapcat-obeys-reduced
  (is (= [1 "0" 2 "1" 3]
        (->> (concat (range 100) (lazy-seq (throw (Exception. "Too eager"))))
          (r/mapcat (juxt inc str))
          (r/take 5)
          (into [])))))


(deftest test-sorted-maps
  (let [m (into (sorted-map)
                '{1 a, 2 b, 3 c, 4 d})]
    (is (= "1a2b3c4d" (reduce-kv str "" m))
        "Sorted maps should reduce-kv in sorted order")
    (is (= 1 (reduce-kv (fn [acc k v]
                          (reduced (+ acc k)))
                        0 m))
        "Sorted maps should stop reduction when asked")))

(defspec reduced-always-returns
  (fn [probe to-end]
    (let [len (+ probe to-end 1)
          nums (range len)
          m (zipmap nums nums)]
      (reduced-at-probe m probe)))
  [^{:tag `gen-num} probe ^{:tag `gen-num} to-end]
  (assert (= :foo %)))

(deftest test-fold-runtime-exception
  (is (thrown? IndexOutOfBoundsException
               (let [test-map-count 1234
                     k-fail (rand-int test-map-count)]
                 (r/fold (fn ([])
                           ([ret [k v]])
                           ([ret k v] (when (= k k-fail)
                                        (throw (IndexOutOfBoundsException.)))))
                         (zipmap (range test-map-count) (repeat :dummy)))))))

(deftest test-closed-over-clearing
  ;; this will throw OutOfMemory without proper reference clearing
  (is (number? (reduce + 0 (r/map identity (range 1e8))))))
clojure
(deftest division
  (is (= clojure.core// /))
  (binding [*ns* *ns*]
    (eval '(do (ns foo
                 (:require [clojure.core :as bar])
                 (:use [clojure.test]))
               (is (= clojure.core// bar//))))))

(require '[clojure.string :as s])
(deftest namespaced-maps
  (is (= #:a{1 nil, :b nil, :b/c nil, :_/d nil}
         #:a {1 nil, :b nil, :b/c nil, :_/d nil}
         {1 nil, :a/b nil, :b/c nil, :d nil}))
  (is (= #::{1 nil, :a nil, :a/b nil, :_/d nil}
         #::  {1 nil, :a nil, :a/b nil, :_/d nil}
         {1 nil, :clojure.test-clojure.reader/a nil, :a/b nil, :d nil} ))
  (is (= #::s{1 nil, :a nil, :a/b nil, :_/d nil}
         #::s  {1 nil, :a nil, :a/b nil, :_/d nil}
         {1 nil, :clojure.string/a nil, :a/b nil, :d nil}))
  (is (= (read-string "#:a{b 1 b/c 2}") {'a/b 1, 'b/c 2}))
  (is (= (binding [*ns* (the-ns 'clojure.test-clojure.reader)] (read-string "#::{b 1, b/c 2, _/d 3}")) {'clojure.test-clojure.reader/b 1, 'b/c 2, 'd 3}))
  (is (= (binding [*ns* (the-ns 'clojure.test-clojure.reader)] (read-string "#::s{b 1, b/c 2, _/d 3}")) {'clojure.string/b 1, 'b/c 2, 'd 3})))

(deftest namespaced-map-errors
  (are [err msg form] (thrown-with-msg? err msg (read-string form))
                      Exception #"Invalid token" "#:::"
                      Exception #"Namespaced map literal must contain an even number of forms" "#:s{1}"
                      Exception #"Namespaced map must specify a valid namespace" "#:s/t{1 2}"
                      Exception #"Unknown auto-resolved namespace alias" "#::BOGUS{1 2}"
                      Exception #"Namespaced map must specify a namespace" "#: s{:a 1}"
                      Exception #"Duplicate key: :user/a" "#::{:a 1 :a 2}"
                      Exception #"Duplicate key: user/a" "#::{a 1 a 2}"))

(deftest namespaced-map-edn
  (is (= {1 1, :a/b 2, :b/c 3, :d 4}
         (edn/read-string "#:a{1 1, :b 2, :b/c 3, :_/d 4}")
         (edn/read-string "#:a {1 1, :b 2, :b/c 3, :_/d 4}"))))
logseq/logseq
(ns frontend.pubsub
  "All mults and pubs are collected to this ns.
  vars with suffix '-mult' is a/Mult, use a/tap and a/untap on them. used by event subscribers
  vars with suffix '-pub' is a/Pub, use a/sub and a/unsub on them. used by event subscribers
  vars with suffix '-ch' is chan used by event publishers."
  {:clj-kondo/config {:linters {:unresolved-symbol {:level :off}}}}
  #?(:cljs (:require-macros [frontend.pubsub :refer [def-mult-or-pub chan-of]]))
  (:require [clojure.core.async :as a :refer [chan mult pub]]
            [clojure.core.async.impl.protocols :as ap]
            [malli.core :as m]
            [malli.dev.pretty :as mdp]
            [clojure.pprint :as pp]))

(def-mult-or-pub app-wake-up-from-sleep
  "app wake up from sleep event"
  [:map
   [:last-activated-at :int]
   [:now :int]])

(def-mult-or-pub sync-events
  "file-sync events"
  [:map
   [:event [:enum
            :created-local-version-file
            :finished-local->remote
            :finished-remote->local
            :start
            :pause
            :resume
            :exception-decrypt-failed
            :remote->local-full-sync-failed
            :local->remote-full-sync-failed
            :get-remote-graph-failed
            :get-deletion-logs-failed
            :get-remote-all-files-failed]]
   [:data :map]]
  :topic-fn :event
  :ch-buffer (a/sliding-buffer 10))
replikativ/datahike
(ns datahike.http.writer
  "Remote writer implementation for datahike.http.server through datahike.http.client."
  (:require [datahike.writer :refer [PWriter create-writer create-database delete-database]]
            [datahike.http.client :refer [request-json] :as client]
            [datahike.json :as json]
            [datahike.tools :as dt :refer [throwable-promise]]
            [taoensso.timbre :as log]
            [clojure.core.async :refer [promise-chan put!]]))

(defrecord DatahikeServerWriter [remote-peer conn]
  PWriter
  (-dispatch! [_ arg-map]
    (let [{:keys [op args]} arg-map
          p (promise-chan)
          config (:config @(:wrapped-atom conn))]
      (log/debug "Sending operation to datahike-server:" op)
      (log/trace "Arguments:" arg-map)
      (put! p
            (try
              (request-json :post
                            (str op "-writer")
                            remote-peer
                            (vec (concat [config] args))
                            json/mapper)
              (catch Exception e
                e)))
      p))
  (-shutdown [_])
  (-streaming? [_] false))
hoplon/hoplon
(ns hoplon.binding
  (:refer-clojure :exclude [binding bound-fn])
  (:require [clojure.core  :as clj]
            [cljs.analyzer :as a]))

(defmacro binding
  "See clojure.core/binding."
  [bindings & body]
  (let [env           (assoc &env :ns (a/get-namespace a/*cljs-ns*))
        value-exprs   (take-nth 2 (rest bindings))
        bind-syms     (map #(:name (a/resolve-existing-var env %)) (take-nth 2 bindings))
        bind-syms'    (map (partial list 'quote) bind-syms)
        set-syms      (repeatedly (count bind-syms) gensym)
        setfn         (fn [x y]
                        {:push! `(fn []
                                   (let [z# ~x]
                                     (set! ~x ~y)
                                     (fn [] (set! ~x z#))))})
        thunkmaps     (map setfn bind-syms set-syms)]
    (a/confirm-bindings env bind-syms)
    `(let [~@(interleave set-syms value-exprs)]
       (hoplon.binding/push-thread-bindings ~(zipmap bind-syms' thunkmaps))
       (try ~@body (finally (hoplon.binding/pop-thread-bindings))))))
HumbleUI/HumbleUI
(ns examples
  (:require
    [clojure.core.server :as server]
    [examples.7guis-converter]
    [examples.align]
    [examples.animation]
    [examples.backdrop]
    [examples.blur]
    [examples.bmi-calculator]
    [examples.button]
    [examples.calculator]
    [examples.canvas]
    [examples.canvas-shapes]
    [examples.checkbox]
    [examples.container]
    [examples.effects]
    [examples.errors]
    [examples.event-bubbling]
    [examples.framerate]
    [examples.grid]
    [examples.image-snapshot]
    [examples.label]
    [examples.oklch]
    [examples.paragraph]
    [examples.scroll]
    [examples.settings]
    [examples.slider]
    [examples.stack]
    [examples.state :as state]
    [examples.svg]
    [examples.text-field]
    [examples.text-field-debug]
    [examples.todomvc]
    [examples.toggle]
    [examples.tooltip]
    [examples.tree]
    [examples.treemap]
    [examples.wordle]
    [io.github.humbleui.app :as app]
    [io.github.humbleui.debug :as debug]
    [io.github.humbleui.paint :as paint]
    [io.github.humbleui.window :as window]
    [io.github.humbleui.ui :as ui]))

(def examples
  (sorted-map
    "7 GUIs: Converter" examples.7guis-converter/ui
    "Align" examples.align/ui
    "Animation" examples.animation/ui
    "Backdrop" examples.backdrop/ui
    "Blur" examples.blur/ui
    "BMI Calculator" examples.bmi-calculator/ui
    "Button" examples.button/ui
    "Calculator" examples.calculator/ui
    "Canvas" examples.canvas/ui
    "Canvas Shapes" examples.canvas-shapes/ui
    "Checkbox" examples.checkbox/ui
    "Container" examples.container/ui
    "Effects" examples.effects/ui
    "Errors" examples.errors/ui
    "Event Bubbling" examples.event-bubbling/ui
    "Framerate" examples.framerate/ui
    "Grid" examples.grid/ui
    "Image Snapshot" examples.image-snapshot/ui
    "Label" examples.label/ui
    "OkLCH" examples.oklch/ui
    "Paragraph" examples.paragraph/ui
    "Scroll" examples.scroll/ui
    "Settings" examples.settings/ui
    "Slider" examples.slider/ui
    "Stack" examples.stack/ui
    "SVG" examples.svg/ui
    "Text Field" examples.text-field/ui
    "Text Field Debug" examples.text-field-debug/ui
    "Todo MVC" examples.todomvc/ui
    "Toggle" examples.toggle/ui
    "Tooltip" examples.tooltip/ui
    "Tree" examples.tree/ui
    "Treemap" examples.treemap/ui
    "Wordle" examples.wordle/ui))
puppetlabs/trapperkeeper
(ns puppetlabs.trapperkeeper.app
  (:require [schema.core :as schema]
            [puppetlabs.trapperkeeper.services :as s]
            [clojure.core.async.impl.protocols :as async-prot])
  (:import (clojure.lang IDeref)))

(defprotocol TrapperkeeperApp
  "Functions available on a trapperkeeper application instance"
  (get-service [this service-id] "Returns the service with the given service id")
  (service-graph [this] "Returns the prismatic graph of service fns for this app")
  (app-context [this] "Returns the application context for this app (an atom containing a map)")
  (check-for-errors! [this] (str "Check for any errors which have occurred in "
                                 "the bootstrap process.  If any have "
                                 "occurred, throw a `java.lang.Throwable` with "
                                 "the contents of the error.  If none have "
                                 "occurred, return the input parameter."))
  (init [this] "Initialize the services")
  (start [this] "Start the services")
  (stop [this] [this throw?] "Stop the services")
  (restart [this] "Stop and restart the services"))