Public Vars

Back

sequence (clj)

(source)

function

(sequence coll) (sequence xform coll) (sequence xform coll & colls)
Coerces coll to a (possibly empty) sequence, if it is not already one. Will not force a lazy seq. (sequence nil) yields (), When a transducer is supplied, returns a lazy sequence of applications of the transform to the items in coll(s), i.e. to the set of first items of each coll, followed by the set of second items in each coll, until any one of the colls is exhausted. Any remaining items in other colls are ignored. The transform should accept number-of-colls arguments

Examples

clojure/core.typed
(ns ^:skip-wiki clojure.core.typed.ann.clojure
  "Type annotations for the base Clojure distribution."
  (:require [#?(:clj clojure.core.typed
                :cljs cljs.core.typed)
             :refer [defalias] :as t]))

(defalias
  ^{:doc "A type that can be used to create a sequence of member type x."
    :forms '[(Seqable t)]}
  t/Seqable
  (t/TFn [[x :variance :covariant]]
         #?(:clj (clojure.lang.Seqable x)
            :cljs (cljs.core/ISeqable x))))

(defalias
  ^{:doc "A non-empty lazy sequence of type t"
    :forms '[(NonEmptyLazySeq t)]}
  t/NonEmptyLazySeq
  (t/TFn [[t :variance :covariant]]
       (t/I (clojure.lang.LazySeq t)
            t/NonEmptyCount)))

(defalias
  ^{:doc "A type that can be used to create a sequence of member type x
         with count greater than 0."
    :forms '[(NonEmptySeqable t)]}
  t/NonEmptySeqable 
  (t/TFn [[x :variance :covariant]]
         (t/I (t/Seqable x)
              t/NonEmptyCount)))

(defalias
  ^{:doc "A type that can be used to create a sequence of member type x
         with count 0."
    :forms '[(EmptySeqable t)]}
  t/EmptySeqable
  (t/TFn [[x :variance :covariant]]
         (t/I (t/Seqable x)
              t/EmptyCount)))

(defalias
  ^{:doc "A persistent sequence of member type x."
    :forms '[(Seq t)]}
  t/Seq
  (t/TFn [[x :variance :covariant]]
         (clojure.lang.ISeq x)))

(defalias
  ^{:doc "A persistent sequence of member type x with count greater than 0."
    :forms '[(NonEmptySeq t)]}
  t/NonEmptySeq
  (t/TFn [[x :variance :covariant]]
         (t/I (t/Seq x)
              t/NonEmptyCount)))

(defalias
  ^{:doc "A persistent sequence of member type x with count greater than 0, or nil."
    :forms '[(NilableNonEmptySeq t)]}
  t/NilableNonEmptySeq
  (t/TFn [[x :variance :covariant]]
         (t/Nilable
           (t/NonEmptySeq x))))

(defalias
  ^{:doc "A Clojure sequential sequence. Seq's aren't always Sequential."
    :forms '[(SequentialSeq t)]}
  t/SequentialSeq
  (t/TFn [[x :variance :covariant]]
         (t/I t/Sequential
              (clojure.lang.ISeq x))))
mikera/core.matrix
   WARNING: because they lack efficient indexed access, sequences will perform badly for most
   array operations. In general they should be converted to other implementations before use."
  (:require [clojure.core.matrix.protocols :as mp]
            [clojure.core.matrix.implementations :as imp]
    #?(:clj [clojure.core.matrix.macros :refer [scalar-coerce error]]))
  #?(:clj (:import [clojure.lang ISeq])
     :cljs (:require-macros [clojure.core.matrix.macros :refer [scalar-coerce error]])))

(extend-protocol mp/PImplementation
  ISeq
    (implementation-key [m] :sequence)
    (meta-info [m]
      {:doc "Core.matrix implementation for Clojure ISeq objects"})
    (new-vector [m length]
      (mp/new-vector [] length))
    (new-matrix [m rows columns]
      (mp/new-matrix [] rows columns))
    (new-matrix-nd [m dims]
      (mp/new-matrix-nd [] dims))
    (construct-matrix [m data]
      (mp/coerce-param [] data))
    (supports-dimensionality? [m dims]
      true))

(extend-protocol mp/PFunctionalOperations
  ISeq
    (element-seq [m]
      (if (== 0 (long (mp/dimensionality (first m))))
        m ;; handle 1D case, just return this sequence unchanged
        (mapcat mp/element-seq m)))
    (element-map
      ([m f]
        (mapv #(mp/element-map % f) m))
      ([m f a]
        (let [[m a] (mp/broadcast-compatible m a)]
          (mapv #(mp/element-map % f %2) m (mp/get-major-slice-seq a))))
      ([m f a more]
        (let [[m a & more] (apply mp/broadcast-compatible m a more)] ; FIXME
          (mapv #(mp/element-map % f %2 %3) m (mp/get-major-slice-seq a) (map mp/get-major-slice-seq more)))))
    (element-map!
      ([m f]
        (error "Sequence arrays are not mutable!"))
      ([m f a]
        (error "Sequence arrays are not mutable!"))
      ([m f a more]
        (error "Sequence arrays are not mutable!")))
    (element-reduce
      ([m f]
        (reduce f (mapcat mp/element-seq m)))
      ([m f init]
        (reduce f init (mapcat mp/element-seq m)))))
hraberg/deuce
(ns deuce.emacs.menu
  (:use [deuce.emacs-lisp :only (defun defvar)])
  (:require [clojure.core :as c])
  (:refer-clojure :exclude []))

  When MENU is a keymap or a list of keymaps, the return value is the
  list of events corresponding to the user's choice. Note that
  `x-popup-menu' does not actually execute the command bound to that
  sequence of events.

  If POSITION is nil, don't display the menu at all, just precalculate the
  cached information about equivalent key sequences.
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))))

(t/defalias
  ^{:doc "A type that can be used to create a sequence of member type x
         with count greater than 0."
    :forms '[(NonEmptySeqable x)]}
  t/NonEmptySeqable 
  (t/TFn [[x :variance :covariant]]
         (t/I (t/Seqable x)
              t/NonEmptyCount)))

(t/defalias
  ^{:doc "A type that can be used to create a sequence of member type x
         with count 0."
    :forms '[(EmptySeqable x)]}
  t/EmptySeqable
  (t/TFn [[x :variance :covariant]]
         (t/I (t/Seqable x)
              t/EmptyCount)))

(t/defalias
  ^{:doc "A persistent sequence of member type x."
    :forms '[(Seq x)]}
  t/Seq
  (t/TFn [[x :variance :covariant]]
         #?(:clj (clojure.lang.ISeq x)
            :cljs (t/I (cljs.core/ISeq x)
                       cljs.core/IWithMeta
                       cljs.core/IMeta
                       (t/Seqable x)
                       (cljs.core/IIterable x)
                       ;(cljs.core/INext x)
                       cljs.core/ICollection
                       cljs.core/IEmptyableCollection
                       cljs.core/ISequential
                       cljs.core/IEquiv))))

(t/defalias
  ^{:doc "A persistent sequence of member type x with count greater than 0."
    :forms '[(NonEmptySeq x)]}
  t/NonEmptySeq
  (t/TFn [[x :variance :covariant]]
         (t/I (t/Seq x)
              t/NonEmptyCount)))

(t/defalias
  ^{:doc "A persistent sequence of member type x with count greater than 0, or nil."
    :forms '[(NilableNonEmptySeq x)]}
  t/NilableNonEmptySeq
  (t/TFn [[x :variance :covariant]]
         (t/Nilable
           (t/NonEmptySeq x))))

(t/defalias
  ^{:doc "A persistent sequence with count greater than 0, or nil."
    :forms '[AnyNilableNonEmptySeq]}
  t/AnyNilableNonEmptySeq
  (t/NilableNonEmptySeq t/Any))

(t/defalias
  ^{:doc "A Clojure sequential sequence. Seq's aren't always Sequential."
    :forms '[(SequentialSeq x)]}
  t/SequentialSeq
  (t/TFn [[x :variance :covariant]]
         (t/I t/Sequential
              (t/Seq x))))

cc/map-indexed (t/All [x y] (t/IFn [[t/Int x :-> y] :-> (t/Transducer x y)]
                                   [[t/Int x :-> y] (t/Seqable x) :-> (t/ASeq y)]))
cc/keep-indexed (t/All [a c] (t/IFn [[t/Int a :-> (t/U nil c)] :-> (t/Transducer a c)]
                                    [[t/Int a :-> (t/U nil c)] (t/Seqable a) :-> (t/Seq c)]))
cc/bounded-count [(t/U t/Counted t/AnySeqable) :-> t/Int]
cc/keep (t/All [a b] (t/IFn [[a :-> (t/Option b)] :-> (t/Transducer a b)]
                            [[a :-> (t/Option b)] (t/Seqable a) :-> (t/ASeq b)]))
cc/dedupe (t/All [x] (t/IFn [:-> (t/Transducer x x)]
                            [(t/Seqable x) :-> (t/ASeq x)]))
cc/random-sample (t/All [x] (t/IFn [t/Num :-> (t/Transducer x x)]
                                   [t/Num (t/Seqable x) :-> (t/ASeq x)]))
cc/halt-when (t/All [x] (t/IFn [[x :-> t/Any] 
                                ;; TODO opens a can of worms. requires knowledge of transduction context.
                                ;; overrides final value of `into`, while doing nothing in `sequence`.
                                ;(t/Option [t/Any v :-> t/Any]) :?
                                :-> (t/Transducer x x)]
                               ))

cc/sequence (t/All [a b] (t/IFn [(t/Seqable a) :-> (t/ASeq a)]
                                ;;TODO rest arity
                                [(t/Transducer a b) (t/Seqable a) :-> (t/ASeq b)]))
cc/find (t/All [x y]
               (t/IFn [nil t/Any :-> nil]
                      [(t/Nilable (t/Associative x y)) t/Any :-> (t/Nilable (t/AMapEntry x y))]
                      ;#?(:clj [(t/Nilable (t/U (t/Associative t/Any t/Any) java.util.Map)) t/Any :-> (t/Nilable (java.util.Map$Entry t/Any t/Any))])
                      ;;TODO TransientAssociative2
                      ))
nubank/nodely
(ns nodely.samples.tutorial
  (:require [nodely.api.v0 :as nodely :refer [>value >leaf >if >cond >sequence >and >or]]
            [clojure.core.async :as async]))

;; A sequence node is used to express a function mapping over a sequential value
;; The first argument is a dependency to a sequential value
;; The second argument is a function to be applied to each element of the sequence
(def a-sequence (>sequence inc ?a))

(nodely/eval-node-with-values a-sequence {:a [1 2 3]})
;; => [2 3 4]