Public Vars

Back

interleave (clj)

(source)

function

(interleave) (interleave c1) (interleave c1 c2) (interleave c1 c2 & colls)
Returns a lazy seq of the first item in each coll, then the second etc.

Examples

originrose/cortex
(ns cortex.optimise.util-test
  (:refer-clojure :exclude [defonce])
  (:require [cortex.optimise.util :refer :all]
            [clojure.core.matrix :as m]
            [clojure.test :refer :all]))

(deftest interleave-all-test
  (is (= (interleave-all) []))
  (is (= (interleave-all (range 5)) (range 5)))
  (is (= (interleave-all [:a :b :c] [:d :e] [:f :g :h :i])
         [:a :d :f :b :e :g :c :h :i])))
originrose/cortex
(ns cortex.util-test
  (:refer-clojure :exclude [defonce])
  (:require
    #?(:cljs [cljs.test :refer-macros [deftest is testing]]
       :clj [clojure.test :refer [deftest is testing]])
    [clojure.core.matrix :as m]
    [clojure.string :as str]
    [cortex.util :refer :all]))

(deftest interleave-all-test
  (is (= (interleave-all) []))
  (is (= (interleave-all (range 5)) (range 5)))
  (is (= (interleave-all [:a :b :c] [:d :e] [:f :g :h :i])
         [:a :d :f :b :e :g :c :h :i])))
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))))))
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/interpose (t/All [x] (t/IFn [x :-> (t/Transducer x x)]
                               [x (t/Seqable x) :-> (t/ASeq x)]))
cc/interleave (t/All [x] [(t/Seqable x) :* :-> (t/ASeq x)])
rufoa/try-let
(ns try-let
	(:require
		[clojure.spec.alpha :as s]
		[clojure.core.specs.alpha :as cs]))


(defmacro try-let
	[bindings & body]
	(let [[_ {:keys [thens catches finally]}] (s/conform ::try-let-body body)
	      bindings-destructured (destructure bindings)
	      bindings-ls (take-nth 2 bindings-destructured)
	      gensyms (take (count bindings-ls) (repeatedly gensym))]
		`(let [[ok# ~@gensyms]
				(try
					(let [~@bindings-destructured] [true ~@bindings-ls])
					~@(map
						(fn [stanza]
							(let [[x y z & body] stanza]
								`(~x ~y ~z [false (do ~@body)])))
						catches)
					~@(when finally [finally]))]
			(if ok#
				(let [~@(interleave bindings-ls gensyms)]
					~@thens)
				~(first gensyms)))))

(defmacro try+-let
	[bindings & body]
	(let [[_ {:keys [thens catches else finally]}] (s/conform ::try+-let-body body)
	      bindings-destructured (destructure bindings)
	      bindings-ls (take-nth 2 bindings-destructured)
	      gensyms (take (count bindings-ls) (repeatedly gensym))]
		`(let [[ok# ~@gensyms]
				(slingshot.slingshot/try+
					(let [~@bindings-destructured] [true ~@bindings-ls])
					~@(map
						(fn [stanza]
							(let [[x y z & body] stanza]
								`(~x ~y ~z [false (do ~@body)])))
						catches)
					~@(when else [else])
					~@(when finally [finally]))]
			(if ok#
				(let [~@(interleave bindings-ls gensyms)]
					~@thens)
				~(first gensyms)))))