Skip to content

Instantly share code, notes, and snippets.

@justinmeiners
Created February 7, 2021 22:15
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 justinmeiners/c5e0ca2227f3fb66eab3ba983f9b0862 to your computer and use it in GitHub Desktop.
Save justinmeiners/c5e0ca2227f3fb66eab3ba983f9b0862 to your computer and use it in GitHub Desktop.
func foldBinary<T>(_ list: [T], operation: (T, T) -> T) -> T? {
if let initial = list.first {
return list.dropFirst().reduce(initial, operation)
} else {
return nil
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment