creates the next immutable object by simply modifying the current one
Project description
immerframe
Create the next immutable object by simply modifying the current one
This is a Python port of immer.
Want to do a deep update on a Python data structure without mutating it? No problem:
from immerframe import Proxy, produce
Ant = namedtuple('Ant', 'age')
nested = {
'foo': [
Ant(age=2),
'bar',
],
}
proxy = Proxy()
proxy['foo'][0].age += 1
proxy['foo'].pop()
proxy['qux'] = 99
new_nested = produce(proxy, nested)
new_nested
will now equal
{
'foo': [
Ant(age=3),
],
'qux': 99,
}
while nested
will remain unchanged.
"What about my typing?":
from typing import cast
Cat = namedtuple('Cat', 'name')
proxy = cast(Cat, Proxy())
# continue as before but with autocomplete and type checking!
proxy.name = 'Felix'
immerframe
uses structural sharing, so should be efficient in most cases:
d = {'foo': 1}
l = [d]
proxy = Proxy()
proxy.append(100)
new_l = produce(proxy, l)
assert new_l == [d, 100]
assert new_l[0] is d
immerframe
supports:
dict
slist
sset
stuples
snamedtuples
sattrs
s
Plugins:
immerframe
currently has an attrs
plugin, registering plugins is pretty easy, just mutate the immerframe.plugins
list (see here for the structure of the existing attr plugin).
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
immerframe-0.0.1.tar.gz
(3.8 kB
view hashes)
Built Distribution
Close
Hashes for immerframe-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4dad4550a42e21ee2a77cba04a89301e82dc8cc98c393e49490e163542085588 |
|
MD5 | 81a0c9438761178bcb03f9a3a976dacc |
|
BLAKE2b-256 | e354e74a0958e3c80d4d583aa850d197510a31eed614c5a0cbc69c91964b294a |