Back
last (clj)
(source)variable
(last coll)
Return the last item in coll, in linear time
Examples
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]])
clj-commons/manifold
(ns manifold.stream.async
{:no-doc true}
(:require
[manifold.deferred :as d]
[clojure.core.async :as a]
[manifold.stream
[graph :as g]
[core :as s]]
[manifold
[executor :as executor]
[utils :as utils]])
(:import
[java.util.concurrent.atomic
AtomicReference]))
(s/def-source CoreAsyncSource
[ch ^AtomicReference last-take]
(let [d (d/deferred)
d' (.getAndSet last-take d)
f (fn [_]
(a/take! ch
(fn [msg]
(d/success! d
(if (nil? msg)
(do
(.markDrained this)
default-val)
msg)))))]
(if (d/realized? d')
(f nil)
(d/on-realized d' f f))
d)))
(take [this default-val blocking? timeout timeout-val]
(let [d (d/deferred)
d' (.getAndSet last-take d)
(s/def-sink CoreAsyncSink
[ch ^AtomicReference last-put]
(close [this]
(utils/with-lock lock
(if (s/closed? this)
false
(do
(.markClosed this)
(let [d (.get last-put)
f (fn [_] (a/close! ch))]
(d/on-realized d
(fn [_] (a/close! ch))
nil)
true)))))
:else
(let [d (d/deferred)
d' (.getAndSet last-put d)
f (fn [_]
(a/go
(d/success! d
(boolean
(a/>! ch x)))))]
(if (d/realized? d')
(f nil)
(d/on-realized d' f f))
d))))
(let [d (d/deferred)
d' (.getAndSet last-put d)
f (fn [_]
(a/go
(let [result (a/alt!
[[ch x]] true
(a/timeout timeout) timeout-val
:priority true)]
(d/success! d result))))]
(if (d/realized? d')
(f nil)
(d/on-realized d' f f))
(if blocking?
@d
d))))))
hraberg/deuce
(ns deuce.emacs.undo
(:use [deuce.emacs-lisp :only (defun defvar)])
(:require [clojure.core :as c])
(:refer-clojure :exclude []))
(defvar undo-outer-limit nil
"Outer limit on size of undo information for one command.
At garbage collection time, if the current command has produced
more than this much undo information, it discards the info and displays
a warning. This is a last-ditch limit to prevent memory overflow.
(defvar undo-outer-limit-function nil
"Function to call when an undo list exceeds `undo-outer-limit'.
This function is called with one argument, the current undo list size
for the most recent command (since the last undo boundary).
If the function returns t, that means truncation has been fully handled.
If it returns nil, the other forms of truncation are done.
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/first (t/All [x] (t/IFn [(t/HSequential [x t/Any :*]) :-> x
:object {:id 0 :path [(Nth 0)]}]
[(t/EmptySeqable x) :-> nil]
[(t/NonEmptySeqable x) :-> x]
[(t/Seqable x) :-> (t/Option x)]))
cc/second (t/All [x] (t/IFn [(t/HSequential [t/Any x t/Any :*]) :-> x
:object {:id 0 :path [(Nth 1)]}]
[(t/Option (t/I (t/Seqable x) (t/CountRange 0 1))) :-> nil]
[(t/I (t/Seqable x) (t/CountRange 2)) :-> x]
[(t/Seqable x) :-> (t/Option x)]))
cc/ffirst (t/All [x] [(t/Seqable (t/Seqable x)) :-> (t/Nilable x)])
cc/nfirst (t/All [x] [(t/Seqable (t/Seqable x)) :-> (t/NilableNonEmptyASeq x)])
cc/group-by (t/All [x y] [[x :-> y] (t/Seqable x) :-> (t/Map y (t/NonEmptyAVec x))])
cc/fnext (t/All [x] [(t/Seqable x) :-> (t/Option x)])
cc/nnext (t/All [x] [(t/Seqable x) :-> (t/NilableNonEmptyASeq x)])
cc/nthnext (t/All [x] (t/IFn [nil t/AnyInteger :-> nil]
[(t/Seqable x) t/AnyInteger :-> (t/NilableNonEmptyASeq x)]))
cc/rest (t/All [x] [(t/Seqable x) :-> (t/ASeq x)])
cc/last (t/All [x] (t/IFn [(t/NonEmptySeqable x) :-> x]
[(t/Seqable x) :-> (t/U nil x)]))
cc/butlast (t/All [x] [(t/Seqable x) :-> (t/NilableNonEmptyASeq x)])
cc/next (t/All [x] (t/IFn [(t/Option (t/Coll x)) :-> (t/NilableNonEmptyASeq x)
:filters {:then (& (is (t/CountRange 2) 0)
(! nil 0))
:else (| (is (t/CountRange 0 1) 0)
(is nil 0))}]
[(t/Seqable x) :-> (t/NilableNonEmptyASeq x)]))
cc/take (t/All [x] (t/IFn [t/Int :-> (t/Transducer x x)]
[t/Int (t/Seqable x) :-> (t/ASeq x)]))
cc/drop (t/All [x] (t/IFn [t/Int :-> (t/Transducer x x)]
[t/Int (t/Seqable x) :-> (t/ASeq x)]))
cc/take-last (t/All [x] [t/Int (t/Seqable x) :-> (t/NilableNonEmptyASeq x)])
cc/drop-last (t/All [x] [(t/? t/Int) (t/Seqable x) :-> (t/ASeq x)])
fluree/db
(ns json-ld.query
(:require [clojure.core.async :as async]
[fluree.db.flake :as flake]
[fluree.db.json-ld.api :as fluree]
[fluree.db.util.async :refer [<?? go-try channel?]]
[fluree.db.query.range :as query-range]
[fluree.db.constants :as const]
[fluree.db.dbproto :as dbproto]
[fluree.db.did :as did]
[fluree.json-ld :as json-ld]
[fluree.db.indexer.default :as indexer]
[fluree.db.indexer.proto :as idx-proto]
[fluree.db.util.log :as log]
[fluree.db.index :as index]
[criterium.core :as criterium]
[fluree.db.query.analytical-parse :as q-parse]))
;; should work OK
(def db
@(fluree/stage
ledger
[{:id :ex/brian,
:type :ex/User,
:schema/name "Brian"
:ex/last "Smith"
:schema/email "brian@example.org"
:schema/age 50
:ex/favNums 7
:ex/scores [76 80 15]}
{:id :ex/alice,
:type :ex/User,
:schema/name "Alice"
:ex/last "Smith"
:schema/email "alice@example.org"
:ex/favColor "Green"
:schema/age 42
:ex/favNums [42, 76, 9]
:ex/scores [102 92.5 90]}
{:id :ex/cam,
:type :ex/User,
:schema/name "Cam"
:ex/last "Jones"
:ex/email "cam@example.org"
:schema/age 34
:ex/favNums [5, 10]
:ex/scores [97.2 100 80]
:ex/friend [:ex/brian :ex/alice]}]))
@(fluree/query db {:select ['?name '?last '(sum ?favNums)]
:where [['?s :schema/name '?name]
['?s :ex/last '?last]
['?s :ex/favNums '?favNums]]
:group-by ['?name '?last]})