racket-collections
racket-collections copied to clipboard
Generic collections API for Racket
This is just a sample to address #27 and start to address #30 . It needs feedback from you @lexi-lambda .
In your original talk you suggested that having a better default print representation for streams would make generic collections more user-friendly. In the light of #27 and #28 , what...
For sequences that are `known-finite?`, `take` and `drop` [check the length](https://github.com/lexi-lambda/racket-collections/blob/c4822fc200b0488922cd6e86b4f2ea7cf8c565da/collections-lib/data/collection/sequence.rkt#L266) of the input sequence eagerly before computing the result, so that something like: ``` (take 3 (range 10000000)) ```...
Some APIs do not return known-finite results even when such an inference could reliably be made. These in particular: ``` rest take drop filter map reverse ``` In the seq...
At the moment, Racket's `in-range` [is simply re-provided](https://github.com/lexi-lambda/racket-collections/blob/c4822fc200b0488922cd6e86b4f2ea7cf8c565da/collections-lib/data/collection/sequence.rkt#L14) as `range`. As this doesn't encode known finiteness, it results in unexpected behavior when used with other APIs: ``` (empty? (range 0))...
Some of the built-in Racket sequences provide `start`, `end` and `step` args, like `(in-vector)` and `(in-string)` ([link](https://docs.racket-lang.org/reference/sequences.html?q=sequence-take#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._in-vector%29%29)). There doesn't seem to be an out-of-the-box way to do this with `data/collection`...
https://github.com/lexi-lambda/racket-collections/blob/c4822fc200b0488922cd6e86b4f2ea7cf8c565da/collections-lib/info.rkt#L12
Fixes #23 by modifying the expected return values in the `conj*` and `extend*` contracts to be `collection?` instead of `sequence?` [[the docs](https://docs.racket-lang.org/collections/collections-api.html?q=data%2Fcollection#%28part._collection-functions%29) confirm that this is the intended output]
If a struct type implements `gen:collection` but not `gen:sequence`, then `conj*` and `extend*` result in a contract error. ``` (struct bag (contents) #:transparent #:methods gen:collection [(define (conj col elem) (bag...