Skip to content

Instantly share code, notes, and snippets.

@Achimh3011
Created September 30, 2018 16:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Achimh3011/262acb8bf6d1b61ee7da6c574b662bd1 to your computer and use it in GitHub Desktop.
Save Achimh3011/262acb8bf6d1b61ee7da6c574b662bd1 to your computer and use it in GitHub Desktop.
from pathlib import Path
from typing import List, Callable, Optional, Sequence
class Functor():
def __init__(self, start: int) -> None:
self.start = int(start)
def __call__(self, data: List[int]) -> int:
return self.start + len(data)
def apply(value: List[int], func : Callable[[List[int]],int]):
return func(value)
def test_appply():
res = apply([1,2,3,4,5], Functor(1))
assert res == 5
##################################################################
def accept_all(_: Path) -> bool:
return True
class matching_suffix():
def __init__(self, suffixes: Sequence[str]) -> None:
self.suffixes = {s.lower() for s in suffixes}
def __call__(self, p: Path) -> bool:
return p.suffix.lower() in self.suffixes
def some_func(supported_file_types: Optional[List[str]]) -> None:
if supported_file_types is not None:
file_filter = matching_suffix(supported_file_types)
else:
file_filter = accept_all
some_other_func(file_filter)
def some_other_func(_predicate: Callable[[Path], bool] = accept_all) -> None:
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment