
Racket related, but API design question I’m curious what people prefer…
I have a container type and I’m making a function(s) that extract returns a stream
of values from the container. If the container was an ordered hash, then the functions might be something like…
(ordered-hash->stream h) ;=> stream of all values stored in all keys
(ordered-hash->stream h key) ;=> stream of all values stored at key
(ordered-hash->stream h #:from #:to) ;=> stream of all values from key up to key
Obviously there’s no polymorphism in Racket, so, what does your programming sensibility lean towards…
- A “do all” function with a signature like
(h [key #f] #:from [from #f] #:to [to #f])
, but then the function attempts to do all sorts of error checking (cannot combinekey
with#:from
and#:to
)? - Two functions: one for an exact key and the other with
#:from
and#:to
where if they are not specified it’s the entire container space? I’m heavily leaning towards the second, but then trying to get names. Maybe something like->stream
for the key case and->range
for the from/to case? Maybe there are similar examples in Racket of this already where a naming pattern already exists?

Or… 3. Only support the #:from
- #:to
case, but make it inclusive instead of #:to
being exclusive.

I like option 3, and then you don’t need a keyword for #:from