Closed antonkulaga closed 6 years ago
This might be a little difficult to implement since the current abstractions are built on iterators. Do you have some example usages that might make is more specific on what the expected API would be?
+1
I think something like a collections.Mapping
would be a good abstraction,
maybe mapKeyVal
for seq(dict()).mapKeyVal(lambda k, v: ...)
instead of doing seq(dict().iteritems()).map(lambda (k, v): (k,v))
Other possible operations could be mapKeys
mapValues
etc
collections.Mapping
is an abstract class so it doesn't help in defining an implementation. As things are, everything is built around:
seq
consumes an iterator that doesn't loop again, that "forking" a sequence into two different operations doesn't result in undesired behavior of one being empty and the other not).One might try to implement this as allowing dict
to be a base collection. Then the question becomes how should things like filter
/map
/everything else be implemented? They are expecting to get an iterable, and expected to return an iterable. So, even if a dictionary is the base collection, after any operation it no longer is, which could be quite confusing. The core issue is that everything as is, is built around iterators, not lists specifically.
I am not opposed to implementing something for dictionaries, but I don't see a good way of implementing it. If you have an idea how to implement it though it would be great to hear more.
I'm gonna close this for the time being since there hasn't been a response in a while. Feel free to re-open if you have followup thoughts/comments on my last post
I see only seq collectin type, it would be nice to have also dictionary functions (like map-based functions in scala) together with some docs about them