Back
ancestors (clj)
(source)function
(ancestors tag)
(ancestors h tag)
Returns the immediate and indirect parents of tag, either via a Java type
inheritance relationship or a relationship established via derive. h
must be a hierarchy obtained from make-hierarchy, if not supplied
defaults to the global hierarchy
Examples
clojure/core.typed
(ns clojure.core.typed.test.protocol
(:require [clojure.core.typed :as t :refer [ann-protocol ann-datatype check-ns]]))
;TODO
;(ann-datatype FooPoly []
; :unchecked-ancestors
; [(IFoo Any)])
;(deftype FooPoly []
; IFoo
; (bar [_] 1))
Netflix/PigPen
(deftest test-code$
(test-diff
(code$ :seq
'(require '[pigpen.runtime])
'(var clojure.core/prn)
["a" 'r0/b 'c/d])
'{:type :code
:udf :seq
:init (require (quote [pigpen.runtime]))
:func (var clojure.core/prn)
:args ["a" r0/b c/d]}))
(deftest test-store$
(with-redefs [pigpen.raw/pigsym pigsym-zero]
(test-diff
(store$ "foo" :string {} r0)
'{:type :store
:id store0
:description "foo"
:ancestors [{:id r0
:fields [r0/value]
:field-type :frozen}]
:location "foo"
:args [r0/value]
:storage :string
:opts {:type :store-opts}})))
(deftest test-project$*
(with-redefs [pigpen.raw/pigsym pigsym-zero]
(test-diff
(project$* [(projection-field$ 'r0/value)] {} 'r0)
'{:type :project
:id project0
:description nil
:ancestors [r0]
:fields [project0/value]
:field-type :frozen
:projections [{:type :projection
:expr {:type :field
:field r0/value}
:flatten false
:alias [project0/value]}]
:opts {:type :project-opts}})))
(deftest test-project$
(with-redefs [pigpen.raw/pigsym pigsym-zero]
(test-diff
(project$ [(projection-field$ 'r0/value)] {} r0)
'{:type :project
:id project0
:description nil
:ancestors [{:id r0
:fields [r0/value]
:field-type :frozen}]
:fields [project0/value]
:field-type :frozen
:projections [{:type :projection
:expr {:type :field
:field r0/value}
:flatten false
:alias [project0/value]}]
:opts {:type :project-opts}})))
(deftest test-bind$
(with-redefs [pigpen.raw/pigsym pigsym-zero]
(test-diff
(bind$ '[pigpen.raw-test] `identity {} r0)
'{:type :bind
:id bind0
:description nil
:ancestors [{:id r0
:fields [r0/value]
:field-type :frozen}]
:requires [pigpen.raw-test]
:func clojure.core/identity
:args [r0/value]
:fields [bind0/value]
:field-type-in :frozen
:field-type :frozen
:types nil
:opts {:type :bind-opts}})
(test-diff
(bind$ ['my-ns] `identity
{:args '[r0/key r0/value]
:alias '[val]
:field-type-in :native
:field-type :native}
r1)
'{:type :bind
:id bind0
:description nil
:ancestors [{:id r1
:fields [r1/key r1/value]
:field-type :frozen}]
:requires [my-ns]
:func clojure.core/identity
:args [r0/key r0/value]
:fields [bind0/val]
:field-type-in :native
:field-type :native
:types nil
:opts {:type :bind-opts}})))
(deftest test-sort$
(with-redefs [pigpen.raw/pigsym pigsym-zero]
(test-diff
(sort$ 'key :asc {} r1)
'{:type :sort
:id sort0
:description nil
:ancestors [{:id r1
:fields [r1/key r1/value]
:field-type :frozen}]
:fields [sort0/value]
:field-type :frozen
:key r1/key
:comp :asc
:opts {:type :sort-opts}})))
(deftest test-rank$
(with-redefs [pigpen.raw/pigsym pigsym-zero]
(test-diff
(rank$ {} r1)
'{:type :rank
:id rank0
:description nil
:ancestors [{:id r1
:fields [r1/key r1/value]
:field-type :frozen}]
:fields [rank0/index rank0/key rank0/value]
:field-type :frozen
:opts {:type :rank-opts}})))
(deftest test-filter$
(with-redefs [pigpen.raw/pigsym pigsym-zero]
(test-diff
(filter$ '(and (= foo "a") (> bar 2))
{}
r0)
'{:type :filter
:id filter0
:description nil
:ancestors [{:id r0
:fields [r0/value]
:field-type :frozen}]
:fields [filter0/value]
:field-type :native
:expr (and (= foo "a") (> bar 2))
:opts {:type :filter-opts}})))
(deftest test-take$
(with-redefs [pigpen.raw/pigsym pigsym-zero]
(test-diff
(take$ 1000 {} r0)
'{:type :take
:id take0
:description nil
:ancestors [{:id r0
:fields [r0/value]
:field-type :frozen}]
:n 1000
:fields [take0/value]
:field-type :frozen
:opts {:type :take-opts}})))
(deftest test-sample$
(with-redefs [pigpen.raw/pigsym pigsym-zero]
(test-diff
(sample$ 0.001 {} r0)
'{:type :sample
:id sample0
:description nil
:ancestors [{:id r0
:fields [r0/value]
:field-type :frozen}]
:p 0.0010
:fields [sample0/value]
:field-type :frozen
:opts {:type :sample-opts}})))
(deftest test-distinct$
(with-redefs [pigpen.raw/pigsym pigsym-zero]
(test-diff
(distinct$ {:parallel 20} r0)
'{:type :distinct
:id distinct0
:description nil
:ancestors [{:id r0
:fields [r0/value]
:field-type :frozen}]
:fields [distinct0/value]
:field-type :frozen
:opts {:type :distinct-opts
:parallel 20}})))
(deftest test-concat$
(with-redefs [pigpen.raw/pigsym pigsym-zero]
(test-diff
(concat$ {}
'[{:id r0, :fields [r0/value], :field-type :frozen}
{:id r1, :fields [r1/value], :field-type :frozen}])
'{:type :concat
:id concat0
:description nil
:fields [concat0/value]
:field-type :frozen
:ancestors [{:id r0, :fields [r0/value], :field-type :frozen}
{:id r1, :fields [r1/value], :field-type :frozen}]
:opts {:type :concat-opts}})))
(deftest test-reduce$
(with-redefs [pigpen.raw/pigsym pigsym-zero]
(test-diff
(reduce$ {} r0)
'{:type :reduce
:id reduce0
:description nil
:arg r0/value
:fields [r0/value]
:field-type :frozen
:ancestors [{:id r0
:fields [r0/value]
:field-type :frozen}]
:opts {:type :reduce-opts}})))
(deftest test-group$
(with-redefs [pigpen.raw/pigsym pigsym-zero]
(test-diff
(group$ :group
[:optional :optional]
{}
[{:id 'g1, :fields '[g1/key g1/value], :field-type :frozen}
{:id 'g2, :fields '[g2/key g2/value], :field-type :frozen}])
'{:type :group
:id group0
:description nil
:keys [g1/key g2/key]
:join-types [:optional :optional]
:field-dispatch :group
:fields [group0/group g1/key g1/value g2/key g2/value]
:field-type :frozen
:ancestors [{:id g1, :fields [g1/key g1/value], :field-type :frozen}
{:id g2, :fields [g2/key g2/value], :field-type :frozen}]
:opts {:type :group-opts}})))
(deftest test-join$
(with-redefs [pigpen.raw/pigsym pigsym-zero]
(test-diff
(join$ :join
[:required :required]
{}
[{:id 'g1, :fields '[g1/key g1/value], :field-type :frozen}
{:id 'g2, :fields '[g2/key g2/value], :field-type :frozen}])
'{:type :join
:id join0
:description nil
:keys [g1/key g2/key]
:join-types [:required :required]
:field-dispatch :join
:fields [g1/key g1/value g2/key g2/value]
:field-type :frozen
:ancestors [{:id g1, :fields [g1/key g1/value], :field-type :frozen}
{:id g2, :fields [g2/key g2/value], :field-type :frozen}]
:opts {:type :join-opts}})))
(deftest test-noop$
(with-redefs [pigpen.raw/pigsym (pigsym-inc)]
(test-diff
(noop$ {} r0)
'{:type :noop
:id noop1
:description nil
:args [r0/value]
:fields [noop1/value]
:field-type :frozen
:ancestors [{:id r0
:fields [r0/value]
:field-type :frozen}]
:opts {:type :noop-opts}})))
(deftest test-store-many$
(with-redefs [pigpen.raw/pigsym (pigsym-inc)]
(test-diff
(store-many$ [(store$ "foo" :string {} r0)
(store$ "foo" :string {} r0)])
'{:type :store-many
:id store-many3
:ancestors [{:storage :string
:location "foo"
:args [r0/value]
:ancestors [{:id r0
:fields [r0/value]
:field-type :frozen}]
:type :store
:id store1
:description "foo"
:opts {:type :store-opts}}
{:storage :string
:location "foo"
:args [r0/value]
:ancestors [{:id r0
:fields [r0/value]
:field-type :frozen}]
:type :store
:id store2
:description "foo"
:opts {:type :store-opts}}]})))
Netflix/PigPen
(test-diff
(->> s
(#'pigpen.oven/braise {})
(#'pigpen.pig.oven/dec-rank {})
(#'pigpen.oven/optimize-binds {})
(map #(select-keys % [:projections :ancestors :fields :id :type])))
'[{:type :return, :id return1, :fields [return1/value]}
{:type :rank, :id rank2_0, :fields [rank2/index rank2/value], :ancestors [return1]}
{:type :project
:id project4
:fields [project4/value]
:ancestors [rank2_0]
:projections [{:type :projection
:expr {:type :code
:init (clojure.core/require (quote [pigpen.runtime]))
:func (clojure.core/comp (pigpen.runtime/process->bind (pigpen.runtime/pre-process nil :frozen))
(pigpen.runtime/process->bind (fn [[i v]] [(dec i) v]))
(pigpen.runtime/map->bind (pigpen.runtime/with-ns pigpen.pig.oven-test vector))
(pigpen.runtime/process->bind (pigpen.runtime/post-process nil :frozen)))
:udf :seq
:args [rank2_0/$0 rank2_0/value]}
:flatten true
:alias [project4/value]
:types nil}]}]))))
(test-diff
(->> s
(#'pigpen.oven/braise {})
(#'pigpen.oven/optimize-binds {})
(#'pigpen.pig.oven/split-project {})
(map #(select-keys % [:projections :ancestors :fields :id :type])))
'[{:type :return
:id return1
:fields [return1/value]}
{:type :project
:id project3_0
:fields [project3_0/value0]
:ancestors [return1]
:projections [{:type :projection
:expr {:type :code
:init (clojure.core/require (quote [pigpen.runtime]))
:func (clojure.core/comp (pigpen.runtime/process->bind (pigpen.runtime/pre-process nil :frozen))
(pigpen.runtime/map->bind (pigpen.runtime/with-ns pigpen.pig.oven-test inc))
(pigpen.runtime/process->bind (pigpen.runtime/post-process nil :frozen)))
:udf :seq
:args [return1/value]}
:flatten false
:alias [project3_0/value0]}]}
{:type :project
:id project3
:fields [project3/value]
:ancestors [project3_0]
:projections [{:type :projection
:expr {:type :field
:field project3_0/value0}
:flatten true
:alias [project3/value]
:types nil}]}]))))
typedclojure/typedclojure
End users should use typed.lib.clojure.core.async, which all types here
are qualified under."}
typed.ann.clojure.core.async
(:require [typed.clojure :refer [ann ann-datatype defalias ann-protocol] :as t]
[typed.lib.clojure.core.async :as-alias ta]
[clojure.core.async.impl.protocols :as-alias impl])
(:import (java.util.concurrent.locks Lock)))
(ann-datatype [[w :variance :contravariant]
[r :variance :covariant]]
clojure.core.async.impl.channels.ManyToManyChannel
[]
:unchecked-ancestors [impl/Channel
(impl/ReadPort r)
(impl/WritePort w)])
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 "An associative persistent collection supporting associative operations on keys type k and values type v."
:forms '[(t/Associative k v)]}
t/Associative
(t/TFn [[k :variance :covariant]
[v :variance :covariant]]
#?(:clj (clojure.lang.Associative k v
;;FIXME should be (t/NilableNonEmptySeq t/Any) when IPersistentCollection supports it
t/Any)
:cljs (t/I (cljs.core/IAssociative k v)
;; emulate clojure.lang.Associative's ancestors
(t/Coll t/Any)
(cljs.core/ILookup v)))))
(t/defalias
^{:doc "A hierarchy for use with derive, isa? etc."
:forms '[Hierarchy]}
t/Hierarchy
'{:parents (t/Map t/Any t/Any)
:ancestors (t/Map t/Any t/Any)
:descendants (t/Map t/Any t/Any)})