This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import List | |
def increment_first_by(values: List[int], add_me: int) -> int: | |
return values[0] + add_me | |
def test_increment_first(): | |
assert increment_first_by([1, 2, 3], 5) == 5 + 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import Dict, Iterable, Set, Tuple | |
from more_itertools import map_except | |
def process( | |
names: Iterable[str], whitelisted_names: Set[str], name_to_email: Dict[str, str] | |
) -> Iterable[str]: | |
whitelisted_name_to_email = { | |
name: email for name, email in name_to_email.items() if name in whitelisted_names |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import Dict, Set | |
from more_itertools import flatten | |
def flatten_multivalues(key_to_values: Dict[str, Set[int]]) -> Set[int]: | |
return set(flatten(key_to_values.values())) | |
def test_flattens_multivalue_dicts(): | |
# shamelessly taken from: https://www.elastic.co/blog/found-elasticsearch-from-the-bottom-up |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import Dict, Set | |
def flatten_multivalues(key_to_values: Dict[str, Set[int]]) -> Set[int]: | |
all_values = set() | |
for values in key_to_values.values(): | |
all_values.update(values) | |
return all_values | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import Dict, Iterable, Set, Tuple | |
from more_itertools import partition | |
def process( | |
names: Iterable[str], whitelisted_names: Set[str], name_to_email: Dict[str, str] | |
) -> Tuple[Iterable[str], Iterable[str]]: | |
refused_names, approved_names = partition( | |
lambda name: name in whitelisted_names, names |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from adt import Case, adt | |
@adt | |
class Expression: | |
LITERAL: Case[float] | |
ADD: Case["Expression", "Expression"] | |
SUBTRACT: Case["Expression", "Expression"] | |
MULTIPLY: Case["Expression", "Expression"] | |
DIVIDE: Case["Expression", "Expression"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import Dict, Generic, TypeVar | |
import pytest | |
from adt import Case, adt | |
T = TypeVar("T") | |
@adt | |
class Option(Generic[T]): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from dataclasses import dataclass | |
class Expression: | |
"""Represents an ADT expression""" | |
@dataclass | |
class Literal(Expression): | |
value: float |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from dataclasses import dataclass | |
class State: | |
"""Represents a possible Circuit Breaker state""" | |
@dataclass | |
class Open(State): | |
pass |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from datetime import datetime | |
from pydantic import BaseModel | |
class Event: | |
"""Represents an event""" | |
class Login(BaseModel, Event): |