Skip to content

Instantly share code, notes, and snippets.

@hyphenrf
Created April 20, 2021 11:52
Show Gist options
  • Save hyphenrf/1c74cd6de1b4545971416afe6b48f63f to your computer and use it in GitHub Desktop.
Save hyphenrf/1c74cd6de1b4545971416afe6b48f63f to your computer and use it in GitHub Desktop.
Does this make you angry?
import functools
c = lambda f: lambda g: lambda x: f (g (x))
add = lambda x: lambda y: x + y
const = lambda x: lambda y: x
uncurry = lambda f: lambda x, y: f (x) (y)
succ = add (1)
fold = lambda f: lambda z: lambda xs: functools.reduce(uncurry(f), xs, z)
len = fold (c (const) (succ)) (0)
print (len (range (100))) # stdout: 100
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment