Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Clojure sequences (https://clojure.org/reference/sequences) provide some of what you are looking for:

"Clojure uses the ISeq interface to allow many data structures to provide access to their elements as sequences.

The seq function yields an implementation of ISeq appropriate to the collection.

Seqs differ from iterators in that they are persistent and immutable, not stateful cursors into a collection.

As such, they are useful for much more than foreach - functions can consume and produce seqs, they are thread safe, they can share structure etc."

Seqs do not handle the "here is my requirement, pick a collection for me" feature you want, but rather "here is a collection, run this algorithm"



Right, seq looks like a single way of accessing various collections when you need to access them in a specific manner.

If I want to access the collection iterating through it in read-only manner I'd just use seq. But I'm not guaranteed that ISeq I got will be fast. It will be as fast as possible for my collection, but what I want is to create a sequence where ISeq is fast, and also for example which I can access and modify by index and also where I can add values in front fast, and also possibly some other requirements.

Basically what I want is the ability to specify which operations I need to be fast at creation time, and get appropriate collection for that. And syntax of those operations should not change if requirements change.

Simpler way might be defining which data structures I want my collections to use, and get fast operations enabled by those data structures through common syntax.

For example:

    var mp = string[] is array, set, stack
    mp[5] = 'hello'
    mp.has('hello')
    mp.pop()
are all fast.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: