Hacker News new | ask | show | jobs
by Viliam1234 2446 days ago
In Clojure, some data structures are implemented as "sequable", which means that they are not implemented as sequences, but they can be converted to sequences if needed. Functions for head and tail are also defined for these structures, for example by internally converting them to sequences first. That means that any function that works with sequences can work with these structures, too.

This seems to me like the proper way to have "separation of interface from implementation" and "everything is a list" at the same time. Yeah, everything is an (interface) list, but not necessarily an (implementation) list.

1 comments

Python and Rust both have similar "duck"y features where you can Impl iteration or add the necessary __special__ methods to get iteration features.