Last active
October 14, 2018 13:58
-
-
Save danielt1263/0be3431c880dbbfaa254298850453df3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Sequence+Scan.swift | |
// | |
// Created by Daniel Tartaglia on 10/13/2018. | |
// Copyright © 2018 Daniel Tartaglia. MIT License. | |
// | |
extension Sequence { | |
public func scan<Result>(_ initialResult: Result, _ nextPartialResult: (Result, Element) throws -> Result) rethrows -> [Result] { | |
return try reduce([Result]()) { $0 + [try nextPartialResult($0.last ?? initialResult, $1)] } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment