You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
How about adding a __call__() interface to pyrsistent containers ?
something like
def __call__(self, *args):
# call just return a new container, with more content added.
# current one is untouched
return v(*[k for k in self], *args)
This would , imho, enable clean python syntax integration :
# we already have simple functions for constructing containersfrompyrsistentimportv# Lets create an immutable threethree=v(1, 2, 3)
# we could, just by calling, append into the vectorassertthree(4,5,6) ==v(1,2,3,4,5,6)
# Still immutable three stays the sameassertthree==v(1,2,3)
# to actually 'register' the change, one needs to store the new vectorsix=three(4,5,6)
assertsix==v(1,2,3,4,5,6)
# Incidently EmptyVector == v, because one could hypothetically do :assertEmptyVector(1,2,3) ==v(1,2,3)
I feel this adds a more "functional/lazy" feel to using immutable containers, while providing a good pythonic syntax (and maybe some simplifications in the code ?)
Not sure which container this would be suitable for however. Besides vector and map, the semantic of the container would need to somehow match the structure of python's args and kwargs, and what it means to "add" an element to the container (prepend, append?, insert at key?)
The text was updated successfully, but these errors were encountered:
Thanks for your suggestion! I'm of the opinion though that it's not obvious what "calling" a vector would result in. Although the syntax is nice in a way as presented above I think I'd rather stick with the somewhat more verbose but, to me at least, more obvious ways that are already in place.
How about adding a
__call__()
interface topyrsistent
containers ?something like
This would , imho, enable clean python syntax integration :
I feel this adds a more "functional/lazy" feel to using immutable containers, while providing a good pythonic syntax (and maybe some simplifications in the code ?)
Not sure which container this would be suitable for however. Besides vector and map, the semantic of the container would need to somehow match the structure of python's args and kwargs, and what it means to "add" an element to the container (prepend, append?, insert at key?)
The text was updated successfully, but these errors were encountered: