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 | |
| struct SemanticVersion: ExpressibleByStringLiteral { | |
| let major: UInt8 | |
| let minor: UInt8 | |
| let patch: UInt8 | |
| init(stringLiteral value: String) { | |
| self.init(value) |
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
| /* | |
| The MIT License (MIT) | |
| Copyright (c) 2020 Daniel Illescas Romero | |
| Permission is hereby granted, free of charge, to any person obtaining a copy | |
| of this software and associated documentation files (the "Software"), to deal | |
| in the Software without restriction, including without limitation the rights | |
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
| copies of the Software, and to permit persons to whom the Software is |
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
| class Stream<T> { | |
| var handler: ((T) -> Void)? | |
| func emitValue(_ value: T) { | |
| handler?(value) | |
| } | |
| func listen(_ handler: @escaping (T) -> Void) { | |
| self.handler = handler | |
| } | |
| } |
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 | |
| import GameplayKit | |
| protocol TestStatesDelegate: class { | |
| func onFetch() | |
| func onSuccess() | |
| func onError() | |
| } | |
| enum DataFetchState { |
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 | |
| enum SwitchState: Int, Equatable { | |
| case on = 1, off = 0 | |
| mutating func toggle() { | |
| switch self { | |
| case .on: self = .off | |
| case .off: self = .on | |
| } |
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
| fun String.fmt(args: Map<String, Any>) = Regex("""\{(\w+)\}""").replace(this) { | |
| "${args.getOrDefault(it.groupValues[1], it.groupValues[0])}" | |
| } |
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 | |
| extension String { | |
| func replacingOcurrences(ofPattern pattern: String, _ matchTransform: (NSTextCheckingResult) -> String) -> String { | |
| guard let regex = try? NSRegularExpression(pattern: pattern, options: []) else { | |
| return self | |
| } | |
| var transformedCharacters: [Character] = [] |
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 | |
| @propertyWrapper | |
| public struct Validate<Value> { | |
| fileprivate let _isValid: (Value) -> Bool | |
| public let asserts: Bool | |
| public let useLastValid: Bool | |
| public let message: (Value) -> String |
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 | |
| @propertyDelegate | |
| public struct UserDefault<ValueType> { | |
| public let key: String | |
| public let defaults: UserDefaults | |
| public let defaultValue: () -> ValueType | |
| init(key: String, defaultValue: @autoclosure @escaping () -> ValueType, defaults: UserDefaults = .standard) { |
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 ClosedRange where Bound: BinaryInteger { | |
| var sum: Bound { | |
| let uB = self.upperBound | |
| let lB = self.lowerBound | |
| return ((uB - (lB-1)) * (uB + lB)) / 2 | |
| } | |
| } | |
| extension Range where Bound: BinaryInteger { | |
| var sum: Bound { |