Skip to content

Instantly share code, notes, and snippets.

View hmhmsh's full-sized avatar

shunkun hmhmsh

View GitHub Profile
extension Unicode.Scalar {
var width: UInt32 {
let code = self.value
if (code >= 0 && code <= 128) {
return 1
} else {
return 2
}
}
}
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`)
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
}
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 }
}