Public Vars

Back

mapv (clj)

(source)

function

(mapv f coll) (mapv f c1 c2) (mapv f c1 c2 c3) (mapv f c1 c2 c3 & colls)
Returns a vector 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.

Examples

clojure/core.typed
;copied from clojure.tools.analyzer.passes.constant-lifter
(ns clojure.core.typed.analyzer.common.passes.constant-lifter
  (:require [clojure.core.typed.analyzer.common :as common]
            [clojure.core.typed.analyzer.common.utils :refer [const-val]]))

(defmethod constant-lift :vector
  [{:keys [items form env] :as ast}]
  (if (and (every? :literal? items)
           (empty? (meta form)))
    (merge (dissoc ast :items :children)
           {:op       :const
            ::common/op ::common/const
            :val      (mapv const-val items)
            :type     :vector
            :literal? true})
    ast))

(defmethod constant-lift :map
  [{:keys [keys vals form env] :as ast}]
  (if (and (every? :literal? keys)
           (every? :literal? vals)
           (empty? (meta form)))
    (let [c (into (empty form)
                  (zipmap (mapv const-val keys)
                          (mapv const-val vals)))
          c (if (= (class c) (class form))
              c
              (apply array-map (mapcat identity c)))]
      (merge (dissoc ast :keys :vals :children)
             {:op       :const
              ::common/op ::common/const
              :val      c
              :type     :map
              :literal? true}))
    ast))

(defmethod constant-lift :set
  [{:keys [items form env] :as ast}]
  (if (and (every? :literal? items)
           (empty? (meta form)))
    (merge (dissoc ast :items :children)
           {:op       :const
            ::common/op ::common/const
            :val      (into (empty form) (mapv const-val items))
            :type     :set
            :literal? true})
    ast))
mikera/core.matrix
   WARNING: because they lack efficient indexed access, sequences will perform badly for most
   array operations. In general they should be converted to other implementations before use."
  (:require [clojure.core.matrix.protocols :as mp]
            [clojure.core.matrix.implementations :as imp]
    #?(:clj [clojure.core.matrix.macros :refer [scalar-coerce error]]))
  #?(:clj (:import [clojure.lang ISeq])
     :cljs (:require-macros [clojure.core.matrix.macros :refer [scalar-coerce error]])))

(extend-protocol mp/PSliceSeq2
  ISeq
    (get-slice-seq [m dimension]
      (let [ldimension (long dimension)]
        (cond
         (== ldimension 0) (mp/get-major-slice-seq m)
         (< ldimension 0) (error "Can't get slices of a negative dimension: " dimension)
         :else (mapv #(mp/get-slice m dimension %) (range (mp/dimension-count m dimension)))))))

(extend-protocol mp/PConversion
  ISeq
    (convert-to-nested-vectors [m]
      (if (> (mp/dimensionality (first m)) 0)
        (mapv mp/convert-to-nested-vectors m)
        (vec m))))

(extend-protocol mp/PFunctionalOperations
  ISeq
    (element-seq [m]
      (if (== 0 (long (mp/dimensionality (first m))))
        m ;; handle 1D case, just return this sequence unchanged
        (mapcat mp/element-seq m)))
    (element-map
      ([m f]
        (mapv #(mp/element-map % f) m))
      ([m f a]
        (let [[m a] (mp/broadcast-compatible m a)]
          (mapv #(mp/element-map % f %2) m (mp/get-major-slice-seq a))))
      ([m f a more]
        (let [[m a & more] (apply mp/broadcast-compatible m a more)] ; FIXME
          (mapv #(mp/element-map % f %2 %3) m (mp/get-major-slice-seq a) (map mp/get-major-slice-seq more)))))
    (element-map!
      ([m f]
        (error "Sequence arrays are not mutable!"))
      ([m f a]
        (error "Sequence arrays are not mutable!"))
      ([m f a more]
        (error "Sequence arrays are not mutable!")))
    (element-reduce
      ([m f]
        (reduce f (mapcat mp/element-seq m)))
      ([m f init]
        (reduce f init (mapcat mp/element-seq m)))))

(extend-protocol mp/PMapIndexed
  ISeq
    (element-map-indexed
      ([ms f]
        (mapv (fn [i m] (mp/element-map-indexed m #(apply f (cons i %1) %&)))
              (range (count ms)) ms))
      ([ms f as]
        (let [[ms as] (mp/broadcast-compatible ms as)]
          (mapv (fn [i m a]
                  (mp/element-map-indexed m #(apply f (cons i %1) %&) a))
                (range (count ms)) ms (mp/get-major-slice-seq as))))
      ([ms f as more]
        (let [[ms as & more] (apply mp/broadcast-compatible ms as more)] ; FIXME
          (mapv (fn [i m a & mr]
                  (mp/element-map-indexed m #(apply f (cons i %1) %&) a mr))
                (range (count ms)) ms
                (mp/get-major-slice-seq as)
                (map mp/get-major-slice-seq more)))))
    (element-map-indexed!
      ([m f]
        (error "Sequence arrays are not mutable!"))
      ([m f a]
        (error "Sequence arrays are not mutable!"))
      ([m f a more]
        (error "Sequence arrays are not mutable!"))))
clojureverse/clojurians-log-app
(ns repl.reactions
  (:require [clojurians-log.application :as app]
            [clojure.java.io :as io]
            [clojurians-log.slack-api :as slack]
            [clojurians-log.db.queries :as q]
            [clojurians-log.db.import :as import]
            [clojurians-log.data :as data]
            [clj-slack.emoji :as slack-emoji]
            [clojure.java.io :as io]
            [clojurians-log.datomic :as d]
            [clojure.tools.reader.edn :as edn]
            [clojure.string :as str]
            [clojure.core.async :as async :refer [>!! <! >! go-loop go <!!]]
            [clojure.data.json :as json])
  (:use [clojurians-log.repl]))

  (into {} (map (comp first #(for [alias (:aliases %)] [alias (:emoji %)])) emlist))
  
  (d/transact (conn) default-emojis)
  (d/q '[:find (pull ?e [*]) :where [?e :emoji/shortcode]] (db))
  
  (def emcoll (slack-emoji/list {:api-url "https://slack.com/api"
   ;; TODO: get rid of this global config access
                                 :token ""}))
  
  (doseq [emojis (partition-all 1000 (:emoji emcoll))]
    @(d/transact (conn) (mapv import/emoji->tx emojis)))
  
  (load-demo-data! "../clojurians-log-demo-data2")
  )
re-path/studio
(ns renderer.tools.box
  "This serves as an abstraction for box elements that share the
   :x :y :width :height attributes."
  (:require
   [clojure.core.matrix :as mat]
   [re-frame.core :as rf]
   [renderer.attribute.hierarchy :as hierarchy]
   [renderer.overlay :as overlay]
   [renderer.tools.base :as tools]
   [renderer.utils.units :as units]))

(defmethod tools/render-edit ::tools/box
  [{:keys [attrs key] :as el}]
  (let [{:keys [x y width height]} attrs
        [x y width height] (mapv units/unit->px [x y width height])
        active-page @(rf/subscribe [:element/active-page])
        page-pos (mapv units/unit->px [(-> active-page :attrs :x)
                                       (-> active-page :attrs :y)])
        [x y] (cond-> [x y] (not= (:tag el) :page) (mat/add page-pos))]
    [:g {:key :edit-handlers}
     (map (fn [handler]
            (let [handler (merge handler {:type :handler
                                          :tag :edit
                                          :element key})]
              [overlay/square-handler handler]))
          [{:x x :y y :key :position}
           {:x (+ x width) :y (+ y height) :key :size}])]))

(defmethod tools/bounds ::tools/box
  [{:keys [attrs]}]
  (let [{:keys [x y width height]} attrs
        [x y width height] (mapv units/unit->px [x y width height])]
    [x y (+ x width) (+ y height)]))
re-path/studio
(ns renderer.tools.svg
  "https://www.w3.org/TR/SVG/struct.html#SVGElement"
  (:require
   [clojure.core.matrix :as mat]
   [clojure.string :as str]
   [renderer.element.handlers :as element.h]
   [renderer.tools.base :as tools]
   [renderer.utils.units :as units]))

(defmethod tools/bounds :svg
  [{:keys [attrs]}]
  (let [{:keys [x y width height stroke-width stroke]} attrs
        [x y width height stroke-width-px] (mapv units/unit->px
                                                 [x y width height stroke-width])
        stroke-width-px (if (str/blank? stroke-width) 1 stroke-width-px)
        [x y] (mat/sub [x y]
                       (/ (if (str/blank? stroke) 0 stroke-width-px) 2))
        [width height] (mat/add [width height]
                                (if (str/blank? stroke) 0 stroke-width-px))]
    (mapv units/unit->px [x y (+ x width) (+ y height)])))