Back
sorted-map (clj)
(source)function
(sorted-map & keyvals)
keyval => key val
Returns a new sorted map with supplied mappings. If any keys are
equal, they are handled as if by repeated uses of assoc.
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))
(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")))
jepsen-io/jepsen
(ns yugabyte.ycql.bank
(:refer-clojure :exclude [test])
(:require [clojure.tools.logging :refer [debug info warn]]
[clojure.core.reducers :as r]
[jepsen.client :as client]
[jepsen.checker :as checker]
[jepsen.generator :as gen]
[jepsen.tests.bank :as bank]
[jepsen.checker.timeline :as timeline]
[knossos.op :as op]
[clojurewerkz.cassaforte.client :as cassandra]
[clojurewerkz.cassaforte.cql :as cql]
[clojurewerkz.cassaforte.query :as q :refer :all]
[yugabyte.ycql.client :as c]))
(invoke! [this test op]
(c/with-errors op #{:read}
(case (:f op)
:read
(->> (cql/select-with-ks conn keyspace table-name)
(map (juxt :id :balance))
(into (sorted-map))
(assoc op :type :ok, :value))
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))
cloojure/tupelo
; Copyright (c) Alan Thompson. All rights reserved.
; The use and distribution terms for this software are covered by the Eclipse Public License 1.0
; (http://opensource.org/licenses/eclipse-1.0.php) which can be found in the file epl-v10.html at
; the root of this distribution. By using this software in any fashion, you are agreeing to be
; bound by the terms of this license. You must not remove this notice, or any other, from this
; software.
(ns tst.tupelo.string
(:refer-clojure :exclude [take drop])
;---------------------------------------------------------------------------------------------------
; https://code.thheller.com/blog/shadow-cljs/2019/10/12/clojurescript-macros.html
; http://blog.fikesfarm.com/posts/2015-12-18-clojurescript-macro-tower-and-loop.html
#?(:cljs (:require-macros [tupelo.test]))
(:require
[clojure.test] ; sometimes this is required - not sure why
[clojure.core :as cc]
[tupelo.core :as t :refer [spy spyx spyxx spyx-pretty forv]]
[tupelo.chars :as char]
[tupelo.string :as str]
[tupelo.test :refer [testing is verify verify-focus
is isnt is= isnt= is-set= is-nonblank= is-nonblank-lines=
throws? throws-not?
]]
))
(verify
(testing "single string"
(is (= "" (str/clip 0 "abcdefg")))
(is (= "a" (str/clip 1 "abcdefg")))
(is (= "ab" (str/clip 2 "abcdefg")))
(is (= "abc" (str/clip 3 "abcdefg")))
(is (= "abcd" (str/clip 4 "abcdefg")))
(is (= "abcde" (str/clip 5 "abcdefg"))))
(testing "two strings"
(is (= "" (str/clip 0 "abc defg")))
(is (= "a" (str/clip 1 "abc defg")))
(is (= "ab" (str/clip 2 "abc defg")))
(is (= "abc" (str/clip 3 "abc defg")))
(is (= "abc " (str/clip 4 "abc defg")))
(is (= "abc d" (str/clip 5 "abc defg"))))
(testing "two strings & char"
(is (= "" (str/clip 0 "ab" \c "defg")))
(is (= "a" (str/clip 1 "ab" \c "defg")))
(is (= "ab" (str/clip 2 "ab" \c "defg")))
(is (= "abc" (str/clip 3 "ab" \c "defg")))
(is (= "abcd" (str/clip 4 "ab" \c "defg")))
(is (= "abcde" (str/clip 5 "ab" \c "defg"))))
(testing "two strings & digit"
(is (= "" (str/clip 0 "ab" 9 "defg")))
(is (= "a" (str/clip 1 "ab" 9 "defg")))
(is (= "ab" (str/clip 2 "ab" 9 "defg")))
(is (= "ab9" (str/clip 3 "ab" 9 "defg")))
(is (= "ab9d" (str/clip 4 "ab" 9 "defg")))
(is (= "ab9de" (str/clip 5 "ab" 9 "defg"))))
(testing "vector"
(is (= "" (str/clip 0 [1 2 3 4 5])))
(is (= "[" (str/clip 1 [1 2 3 4 5])))
(is (= "[1" (str/clip 2 [1 2 3 4 5])))
(is (= "[1 2" (str/clip 4 [1 2 3 4 5])))
(is (= "[1 2 3 4" (str/clip 8 [1 2 3 4 5])))
(is (= "[1 2 3 4 5]" (str/clip 16 [1 2 3 4 5]))))
(testing "map"
(is (= "" (str/clip 0 (sorted-map :a 1 :b 2))))
(is (= "{" (str/clip 1 (sorted-map :a 1 :b 2))))
(is (= "{:" (str/clip 2 (sorted-map :a 1 :b 2))))
(is (= "{:a " (str/clip 4 (sorted-map :a 1 :b 2))))
(is (= "{:a 1, :" (str/clip 8 (sorted-map :a 1 :b 2))))
(is (= "{:a 1, :b 2}" (str/clip 16 (sorted-map :a 1 :b 2)))))
(testing "set"
(let [tst-set (sorted-set 5 4 3 2 1)]
(is (= "" (str/clip 0 tst-set)))
(is (= "#" (str/clip 1 tst-set)))
(is (= "#{" (str/clip 2 tst-set)))
(is (= "#{1 " (str/clip 4 tst-set)))
(is (= "#{1 2 3 " (str/clip 8 tst-set)))
(is (= "#{1 2 3 4 5}" (str/clip 16 tst-set))))))
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/set (t/All [x] [(t/Seqable x) :-> #?(:cljs (t/Set x)
:default (PersistentHashSet x))])
cc/hash-set (t/All [x] [x :* :-> #?(:cljs (t/Set x)
:default (PersistentHashSet x))])
;TODO
;cc/hash-map (t/All [x y z :..]
; (t/IFn [(t/cat z z) :.. z :-> (t/Assoc '{} z :.. z)]
; [(t/cat x y) :* :-> (t/Map x y)]))
cc/hash-map (t/All [x y] [(t/cat x y) :* :-> (t/Map x y)])
cc/array-map (t/All [x y] [(t/cat x y) :* :-> (t/Map x y)])
cc/sorted-map (t/All [x y] [(t/cat x y) :* :-> (t/SortedMap x y)])
cc/sorted-map-by (t/All [x y] [[x x :-> t/Int] (t/cat x y) :* :-> (t/SortedMap x y)])
cc/sorted-set (t/All [x] [x :* :-> (t/SortedSet x)])
;;FIXME use t/Comparator for first arg
cc/sorted-set-by (t/All [x] [[x x :-> t/Int] x :* :-> (t/SortedSet x)])
cc/list (t/All [x] [x :* :-> (#?(:clj PersistentList :cljs t/List) x)])
;cc/list* (t/All [x] [x :* (t/Seqable x) :-> (t/NilableNonEmptyASeq x)])
cc/list* (t/All [x] (t/IFn [(t/Seqable x) :-> (t/NilableNonEmptyASeq x)]
[x (t/Seqable x) :-> (t/NonEmptyASeq x)]
[x x (t/Seqable x) :-> (t/NonEmptyASeq x)]
[x x x (t/Seqable x) :-> (t/NonEmptyASeq x)]
[x x x x (t/Seqable x) :-> (t/NonEmptyASeq x)]
[x x x x x (t/Seqable x) :-> (t/NonEmptyASeq x)]
[x x x x x x (t/Seqable x) :-> (t/NonEmptyASeq x)]
[x x x x x x x (t/Seqable x) :-> (t/NonEmptyASeq x)]
[x x x x x x x x (t/Seqable x) :-> (t/NonEmptyASeq x)]
[x x x x x x x x x (t/Seqable x) :-> (t/NonEmptyASeq x)]
[x x x x x x x x x x (t/Seqable x) :-> (t/NonEmptyASeq x)]))
clojure/data.int-map
(ns clojure.data.benchmark
(:use
[clojure.test])
(:require
[clojure.core.reducers :as r]
[clojure.data.int-map :as i]
[criterium.core :as c])
(:import
[java.util
BitSet]
[clojure.data.int_map
PersistentIntMap]))
(println "\ninto (sorted-map) unordered")
(c/quick-bench
(into (sorted-map) entries))
(println "\ninto (sorted-map) ordered")
(c/quick-bench
(into (sorted-map) ordered-entries))
(let [m (into (sorted-map) entries)
r (java.util.Random.)]
(println "\nget (sorted-map)")
(c/quick-bench
(get m 1000)))