CrossClj

0.0.2 docs

SourceDocs



RECENT

    n01se/deltype

    Clojars

    Jun 30, 2014


    OWNER
    Jonathan Claggett
    Lonocloud
    Nashua, NH
    jonathan@claggett.org

    Readme

    Index of all namespaces


    « Project + dependencies

    Delegation support in deftype and reify. This is an experimental augmentation to support automatic delegation to specified fields with a specified interface.

    The README below is fetched from the published project artifact. Some relative links may be broken.

    deltype

    An experiment in automatic delegations and Clojure’s deftype.

    The goal is to make it easy to define new data types that are based off of Clojure’s standard persistent collections (i.e., maps, sets, lists, and vectors). The challenge is to do it without using traditional inheritence. The approach is to delegate method calls to a specific field of the new type.

    Usage

    (require '[n01se.deltype :as d])
    
    (d/deftype MapType [map-field]
      :delegate [map-field n01se.deltype.IMap])
    
    (def foo (MapType. {}))
    
    (assoc foo :a 1) ;=> {:a 1}
    (class foo) ;=> MapType
    

    Links