def each(li, fn):
  if len(li) == 0: return
  head, *tail = li 
  fn(head)
  return each(tail, fn)

def map(li, fn):
  if len(li) == 0: return []
  head, *tail = li 
  return [fn(head)] + map(tail, fn)

def filter(li, fn):
  if len(li) == 0: return []
  head, *tail = li 
  if fn(head):
    return [head] + filter(tail, fn)
  return filter(tail, fn)

def reduce(li, fn, acc=0):
  if len(li) == 0: return acc 
  head, *tail = li 
  acc = fn(acc, head)
  return reduce(tail, fn, acc)

nums = [1, 2, 3, 4, 5]
print(each(nums, print))
print(map(nums, lambda x: x*10))
print(filter(nums, lambda x: x%2))
print(reduce(nums, (lambda a, c: a + c), 0))

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: