Skip to content

Instantly share code, notes, and snippets.

@EkremDincel
Created August 24, 2020 10:54
Show Gist options
  • Save EkremDincel/f9b9ce42469cd287f307ec3861ae30bb to your computer and use it in GitHub Desktop.
Save EkremDincel/f9b9ce42469cd287f307ec3861ae30bb to your computer and use it in GitHub Desktop.
from functools import reduce, partial
import itertools as it
from operator import itemgetter, methodcaller
def reversed_partial(f, *args, **kwargs):
def wrapper(*_args, **_kwargs):
f(*_args, *args, **_kwargs, **kwargs)
return wrapper
def unpack(iterable):
for i in iterable:
yield from i
def fmap(obj, functions):
for f in functions:
yield f(obj)
class Subsequence():
def __init__(self, sequence):
self.sequence = sequence
self.start = 0
self.finish = len(sequence)
def upto(self, finish):
self.finish = self.start + finish
return self
def startfrom(self, start):
self.start += start
return self
def between(self, start, finish):
self.finish = self.start + finish
self.start += start
def __getitem__(self, index: int):
return self.sequence[self.start + index]
def __len__(self):
return self.finish - self.start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment