Public Vars

Back

filterv (clj)

(source)

function

(filterv pred coll)
Returns a vector of the items in coll for which (pred item) returns logical true. pred must be free of side-effects.

Examples

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/filter (t/All [x y] (t/IFn
                         [[x :-> t/Any :filters {:then (is y 0)}] :-> (t/Transducer x y)]
                         [[x :-> t/Any :filters {:then (! y 0)}] :-> (t/Transducer x (t/I x (t/Not y)))]
                         [[x :-> t/Any] :-> (t/Transducer x x)]
                         [[x :-> t/Any :filters {:then (is y 0)}] (t/Seqable x) :-> (t/ASeq y)]
                         [[x :-> t/Any :filters {:then (! y 0)}] (t/Seqable x) :-> (t/ASeq (t/I x (t/Not y)))]
                         [[x :-> t/Any] (t/Seqable x) :-> (t/ASeq x)]))
cc/filterv (t/All [x y] (t/IFn
                          [[x :-> t/Any :filters {:then (is y 0)}] (t/Seqable x) :-> (t/AVec y)]
                          [[x :-> t/Any] (t/Seqable x) :-> (t/AVec x)]))
cc/remove (t/All [x y] (t/IFn
                         [[x :-> t/Any :filters {:else (is y 0)}] :-> (t/Transducer x y)]
                         [[x :-> t/Any :filters {:else (! y 0)}] :-> (t/Transducer x (t/I x (t/Not y)))]
                         [[x :-> t/Any] :-> (t/Transducer x x)]
                         [[x :-> t/Any :filters {:else (is y 0)}] (t/Seqable x) :-> (t/ASeq y)]
                         [[x :-> t/Any :filters {:else (! y 0)}] (t/Seqable x) :-> (t/ASeq (t/I x (t/Not y)))]
                         [[x :-> t/Any] (t/Seqable x) :-> (t/ASeq x)]))
fluree/db
(ns fluree.db.policy.subj-flakes-test
  (:require [clojure.test :refer [deftest is testing]]
            [fluree.db.test-utils :as test-utils]
            [fluree.db.json-ld.api :as fluree]
            [fluree.db.did :as did]
            [fluree.db.permissions-validate :as policy-enforce]
            [clojure.core.async :as async]
            [fluree.db.flake :as flake]))

          ssn-iri (fluree/expand-iri context :schema/ssn)
          ssn-sid @(fluree/internal-id db ssn-iri)]
      (is (= 0
             (count (filterv #(= ssn-sid (flake/p %)) alice-db-john)))
          "Alice cannot see John's ssn.")
      (is (= 5
             (count alice-db-john))
          "Alice can see John's everything but ssn.")

      (is (= 1
             (count (filterv #(= ssn-sid (flake/p %)) alice-db-alice)))
          "Alice cannot see her own ssn.")
      (is (= 7
             (count alice-db-alice))
          "Alice can see her own everything.")
PacktPublishing/Clojure-Programming-Cookbook
(ns asyncing.withmapv
	(:require [clojure.core.async :as async]))

(def out
  (async/thread
    (loop [cs [c1 c2] vs []]
      (let [[v p] (async/alts!! cs)
            cs (filterv #(not= p %) cs)
            vs (conj vs v)]
        (if (seq cs)
          (recur cs vs)
          vs)))))