Back
concat (clj)
(source)function
(concat)
(concat x)
(concat x y)
(concat x y & zs)
Returns a lazy seq representing the concatenation of the elements in the supplied colls.
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-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 [])))))
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))
(defmethod create-database :datahike-server
[& args]
(let [p (throwable-promise)
{:keys [writer] :as config} (first args)]
;; redirect call to remote-peer as writer config
(deliver p (try (->
(request-json :post
"create-database-writer"
writer
(vec (concat [(-> config
(assoc :remote-peer writer)
(dissoc :writer))]
(rest args))))
(dissoc :remote-peer))
(catch Exception e
e)))
p))
(defmethod delete-database :datahike-server
[& args]
(let [p (throwable-promise)
{:keys [writer] :as config} (first args)]
;; redirect call to remote-peer as writer config
(deliver p (try
(-> (request-json :post
"delete-database-writer"
writer
(vec (concat [(-> config
(assoc :remote-peer writer)
(dissoc :writer))]
(rest args))))
(dissoc :remote-peer))
(catch Exception e
e)))
p))
hraberg/deuce
(ns deuce.emacs.callproc
(:use [deuce.emacs-lisp :only (defun defvar) :as el])
(:require [clojure.core :as c]
[clojure.string :as s]
[clojure.java.io :as io]
[clojure.java.shell :as sh]
[deuce.emacs.buffer :as buffer]
[deuce.emacs.data :as data]
[deuce.emacs.editfns :as editfns])
(:import [java.io File])
(:refer-clojure :exclude []))
If BUFFER is 0, `call-process' returns immediately with value nil.
Otherwise it waits for PROGRAM to terminate
and returns a numeric exit status or a signal description string.
If you quit, the process is killed with SIGINT, or SIGKILL if you quit again."
(let [opts (if infile [:in (io/file infile)] [])
no-wait? (= 0 buffer)
buffer (or no-wait?
(and (data/consp buffer) (= :file (data/car buffer)) (data/cdr buffer))
(and (true? buffer) (buffer/current-buffer))
(el/check-type 'bufferp (or (when (data/consp buffer) (data/car buffer))
buffer (buffer/current-buffer))))
stderr (when (data/consp buffer) (data/cdr buffer))
runner (if no-wait? #(do (future-call %) nil) #(%))]
(runner #(let [{:keys [exit out err]}
(apply sh/sh (concat (cons program args) opts))]
(when (data/bufferp buffer)
(binding [buffer/*current-buffer* buffer]
(editfns/insert out)
(when (true? stderr)
(editfns/insert err))))
(when (string? buffer)
(spit (io/file buffer) out))
(when (string? stderr)
(spit (io/file stderr) err))
exit))))
hraberg/deuce
(ns deuce.emacs.eval
(:use [deuce.emacs-lisp :only (defun defvar)])
(:require [clojure.core :as c]
[deuce.emacs.alloc :as alloc]
[deuce.emacs.data :as data]
[deuce.emacs-lisp.cons :as cons]
[deuce.emacs-lisp :as el])
(:import [clojure.lang Var])
(:refer-clojure :exclude [apply eval macroexpand]))
(defun apply (function &rest arguments)
"Call FUNCTION with our remaining args, using our last arg as list of args.
Then return the value FUNCTION returns.
Thus, (apply '+ 1 2 '(3 4)) returns 10."
(let [rest (last arguments)]
(el/check-type 'listp rest)
(c/apply (cond (symbol? function) (data/symbol-function function)
(data/listp function) (eval function)
:else function) (c/apply alloc/list (concat (butlast arguments) rest)))))
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/concat (t/All [x] [(t/Seqable x) :* :-> (t/ASeq x)])
reborg/parallel
(require '[parallel.core :as p])
(require '[criterium.core :refer [bench quick-bench]])
(require '[clojure.core.reducers :as r])
(def small-overlapping
(into [] (map hash-map
(repeat :samplevalue)
(concat
(shuffle (range 0. 1e5))
(shuffle (range 0. 1e5))
(shuffle (range 0. 1e5))
(shuffle (range 0. 1e5))
(shuffle (range 0. 1e5))))))
(def big-overlapping
(into [] (map hash-map
(repeat :samplevalue)
(concat
(shuffle (range 6e4 1e5))
(shuffle (range 6e4 1e5))
(shuffle (range 6e4 1e5))
(shuffle (range 6e4 1e5))
(shuffle (range 6e4 1e5))))))
(def bigger-data
(into [] (map hash-map
(repeat :samplevalue)
(concat
(shuffle (range 0. 7e5))
(shuffle (range 0. 7e5))
(shuffle (range 0. 7e5))
(shuffle (range 0. 7e5))
(shuffle (range 0. 7e5))))))