Public Vars

Back

take-nth (clj)

(source)

function

(take-nth n) (take-nth n coll)
Returns a lazy seq of every nth item in coll. Returns a stateful transducer when no collection is provided.

Examples

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/take-nth (t/All [x] [t/AnyInteger (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)))))