This file contains hidden or 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
extension Unicode.Scalar { | |
var width: UInt32 { | |
let code = self.value | |
if (code >= 0 && code <= 128) { | |
return 1 | |
} else { | |
return 2 | |
} | |
} | |
} |
This file contains hidden or 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
extension Array { | |
public mutating func remove(where: (Element) -> Bool) { | |
while let index = self.index(where: `where`) { | |
remove(at: index) | |
} | |
} | |
public func removed(where: (Element) -> Bool) -> [Element] { | |
var copy = self | |
copy.remove(where: `where`) |
This file contains hidden or 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
extension Optional { | |
public mutating func ensure(_ f: () throws -> Wrapped) rethrows -> Wrapped { | |
if let x = self { | |
return x | |
} | |
let x = try f() | |
self = x | |
return x | |
} |
This file contains hidden or 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
import Foundation | |
let intJson = #"{ "inUse": 1, "name": "Daiki Matsudate", "twitter": "d_date", "stars": 99999, "occupation": null}"# | |
let boolJson = #"{ "inUse": true, "name": "Daiki Matsudate", "twitter": "d_date", "stars": 99999, "occupation": null}"# | |
protocol Inherits { | |
associatedtype SuperType | |
var `super`: SuperType { get } | |
} |
OlderNewer