Advertisement
This is comment for paste
Prefix sum - Swift
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public extension Collection {
- func inits<T>(_ transform: (SubSequence) throws -> T) rethrows -> [T] {
- try (0...count).map { try transform(prefix($0)) }
- }
- func inits() -> [SubSequence] {
- inits { $0 }
- }
- }
- print([1, 7, 14, 9, 11].inits { $0.reduce(0, +) })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement