You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.2 KiB

  1. from functools import reduce
  2. from inspect import signature
  3. def apply_transforms(data, func):
  4. return func(data)
  5. def bootlegCurry(f):
  6. '''
  7. a bootleg curry.
  8. '''
  9. def _curry(f, remaining):
  10. def inner(*args):
  11. if len(args) >= remaining:
  12. return f(*args)
  13. else:
  14. newfunc = lambda *rem: f(*args, *rem)
  15. return _curry(newfunc, remaining - len(args))
  16. return inner
  17. return _curry(f, len(signature(f).parameters))
  18. def excluding(item_dict, *to_exclude):
  19. excluded = set(to_exclude)
  20. return {key: val for key, val in item_dict.items()
  21. if key not in excluded}
  22. def indentity(x):
  23. return x
  24. def merge(*args):
  25. return reduce(lambda acc, val: acc.update(val) or acc, args, {})
  26. def partition_by(f, coll):
  27. a = []
  28. b = []
  29. for item in coll:
  30. bucket = a if f(item) else b
  31. bucket.append(item)
  32. return a, b
  33. if __name__ == '__main__':
  34. pass
  35. # a = {
  36. # 'a': 111,
  37. # 'b': 111,
  38. # 'c': 111,
  39. # 1: 111
  40. # }
  41. # print(excluding(a, 'a', 'c', 1))