store/[org.clojure/clojure "1.8.0"] clj::clojure.core/ancestors

Official Documentation

Add notes
Arities
==================================================
   [tag]
   [h tag]

Docstring
==================================================
  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

Source

(defn ancestors
  "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"
  {:added "1.0"}
  ([tag] (ancestors global-hierarchy tag))
  ([h tag] (not-empty
            (let [ta (get (:ancestors h) tag)]
              (if (class? tag)
                (let [superclasses (set (supers tag))]
                  (reduce1 into1 superclasses
                    (cons ta
                          (map #(get (:ancestors h) %) superclasses))))
                ta)))))

Example 1

Edit
;; use ancestors to show which classes ArrayList derives from and which
;; interfaces it implements

(ancestors java.util.ArrayList)
;; => #{java.util.Collection java.util.AbstractList java.io.Serializable java.lang.Cloneable java.util.List java.lang.Object java.util.AbstractCollection java.util.RandomAccess java.lang.Iterable}

Example 2

Edit
;; make up a hierarchy a beagle is a sporting breed is a dog is a quadraped is an 
;; animal

(derive ::quadruped ::animal)
;; => nil

(derive ::dog ::quadruped)
;; => nil

(derive ::sporting_breed ::dog)
;; => nil

(derive ::beagle ::sporting_breed)
;; => nil

(ancestors ::beagle)
;; => #{:user/dog :user/sporting_breed :user/animal :user/quadruped}

Uses on crossclj