Add workspace
This commit is contained in:
parent
55c236e336
commit
31ed3c2039
3 changed files with 364 additions and 0 deletions
38
Utils/Utils.swift
Normal file
38
Utils/Utils.swift
Normal file
|
@ -0,0 +1,38 @@
|
|||
import Foundation
|
||||
|
||||
extension Scanner {
|
||||
@discardableResult
|
||||
func string(_ string: String) -> Bool {
|
||||
return scanString(string) != nil
|
||||
}
|
||||
|
||||
func integers() -> [Int] {
|
||||
var numbers: [Int] = []
|
||||
while let num = scanInt() {
|
||||
numbers.append(num)
|
||||
}
|
||||
return numbers
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
extension String {
|
||||
func lines() -> [String] {
|
||||
var result: [String] = []
|
||||
enumerateLines { line, _ in result.append(line) }
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
extension Sequence {
|
||||
func print(_ prefix: String = "") -> Self {
|
||||
Swift.print(prefix, Array(self))
|
||||
return self
|
||||
}
|
||||
}
|
||||
|
||||
extension Collection where Element: Collection {
|
||||
func flatten() -> [Element.Element] {
|
||||
flatMap { $0 }
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue