Skip to content

Instantly share code, notes, and snippets.

@dmwit
Created November 3, 2018 02:03
Show Gist options
  • Save dmwit/81d5f8e99612847a7611a66895863eb8 to your computer and use it in GitHub Desktop.
Save dmwit/81d5f8e99612847a7611a66895863eb8 to your computer and use it in GitHub Desktop.
treefold
foldb1 op = foldb' where
pairwise (x:y:rest) = op x y : pairwise rest
pairwise shortList = shortList
foldb' xs@(_:_:_) = foldb' (pairwise xs)
foldb' [x] = x
foldb op def xs = foldb1 op (def:xs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment