Skip to content

Instantly share code, notes, and snippets.

View btknight's full-sized avatar

Brian Knight btknight

  • Chicago, IL
View GitHub Profile
"""The truth is, I thought it mattered --
I thought that music mattered.
But does it bollocks?
Not compared to how people matter.
"""
from itertools import cycle, repeat
from operator import methodcaller
from typing import List
from typing import Callable, Hashable
class FuncRegistry(dict):
"""Creates a registry of hashable objects to function mappings."""
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
def register_for(self, key: Hashable) -> Callable:
"""Decorator to register functions in the registry.
"""Objects that facilitate parsing values from regex and assigning
those values to other objects.
Classes
Val:
Object that stores the group matches from an re.match() call.
Class methods that change the stored value are chainable.
Functions
"""Helper class to run a chain of callbacks on input data."""
from typing import Callable, Any
class CbChain(object):
"""Chain callbacks together.
Instances of this object are themselves Callable. When called, it passes the supplied arguments to the first
callback in the chain. The result of the first callback is fed to the second, the result of the second fed to
the third, and so on.