Purely Functional Data Structures in Clojure
https://www.amazon.com/gp/product/0521663504
- every data structure in separate namespace
- common API as protocols, however all API functions are duplicated in data structure namespaces (to wrap lazy cases)
- every data structure has own type (eg. LeftistHeap)
- if necessary empty is implemented as another type (eg. EmptyLeftistHeap)
- Clojure interop:
->seqandseq-> Clojure sequence->TYPE(eg.->stack) to convert sequence to desired type->structureto export internal structure as map- Indexed (for destructuring) and Seqable (for
seqcoersion) interfaces are implemented
- no speed or memory optimizations, possible SO exceptions
Two ways:
empty-TYPE(eg.empty-heap) singleton is created for every data structure. Use it and feed with data.->TYPE(eg.->heap) to convert Clojure sequence to a type
This is probably done wrong. I'm using delay and force to implement $ operator.