Skip to content

Instantly share code, notes, and snippets.

@InsertNetan
Last active June 24, 2016 09:37
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 InsertNetan/d74a85524a2e6e5f5c81fdf329ca1f9d to your computer and use it in GitHub Desktop.
Save InsertNetan/d74a85524a2e6e5f5c81fdf329ca1f9d to your computer and use it in GitHub Desktop.
extension Array {
func scanl<T>(initial: T, combine:@noescape (Element, T) -> T) -> [T] {
guard let first = self.first else { return [initial] }
return [initial] + Array(self.dropFirst()).scanl(initial: combine(first, initial), combine: combine)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment