Skip to content

Instantly share code, notes, and snippets.

View Drvanon's full-sized avatar
😀
Ready to get working

Robin Alexander Dorstijn Drvanon

😀
Ready to get working
  • Groningen
View GitHub Profile
@horvatha
horvatha / loose_transform.py
Last active July 26, 2022 07:45
Loose transformation for pyrsistent. Similar to the transform method, but it works even if there are missing keys.
from typing import List, Callable, Union
from pyrsistent import PVector, PMap, ny, freeze
def loose_transform(structure: Union[PVector,PMap], path: List, command: Callable):
if not path:
return command(structure) if callable(command) else command
key_spec = path[0]
if not callable(key_spec):