Skip to content

Instantly share code, notes, and snippets.

@invkrh
Created September 7, 2015 22:24
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 invkrh/a48839774a1a0c03978d to your computer and use it in GitHub Desktop.
Save invkrh/a48839774a1a0c03978d to your computer and use it in GitHub Desktop.
def foldRightViaFoldLeft_1[A, B](l: List[A], z: B)(f: (A, B) => B): B =
foldLeft(l, (x: B) => x)((g, a) => (b: B) => g(f(a, b)))(z)
def foldLeftViaFoldRight[A, B](l: List[A], z: B)(f: (B, A) => B): B =
foldRight(l, (b: B) => b)((a, g) => b => g(f(b, a)))(z)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment