EntilZha / PyFunctional

Python library for creating data pipelines with chain functional programming
http://pyfunctional.pedro.ai
MIT License
2.41k stars 132 forks source link

more on dictionaries #108

Closed antonkulaga closed 6 years ago

antonkulaga commented 7 years ago

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

EntilZha commented 7 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?

linar-jether commented 7 years ago

+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

EntilZha commented 7 years ago

collections.Mapping is an abstract class so it doesn't help in defining an implementation. As things are, everything is built around:

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.

EntilZha commented 6 years ago

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