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 Sequence { | |
| func sorted<T: Comparable>(on propertyAccessor: (Iterator.Element) -> T) -> Array<Iterator.Element> { | |
| return self | |
| .lazy | |
| .map({ (element: $0, sortingProperty: propertyAccessor($0)) }) | |
| .sorted(by: { $0.sortingProperty < $1.sortingProperty }) | |
| .map({ $0.element }) | |
| } | |
| } |
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 Sequence { | |
| func eachPair() -> Zip2Sequence<Self, DropFirstSequence<Self>> { | |
| return zip(self, self.dropFirst()) | |
| } | |
| } | |
| extension Collection { | |
| func indexed() -> [(index: Index, element: Element)] { | |
| return zip(indices, self).map({ (index: $0, element: $1) }) |
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 Character: Strideable { | |
| public typealias Stride = Int | |
| public func distance(to other: Character) -> Character.Stride { | |
| guard let first = self.unicodeScalars.first else { | |
| fatalError() | |
| } | |
| guard let other = other.unicodeScalars.first else { | |
| fatalError() | |
| } |
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 Sequence { | |
| func smallest(_ n: Int, usingTest areInIncreasingOrder: (Element, Element) -> Bool) -> [Element] { | |
| var result = self.prefix(n).sorted(by: areInIncreasingOrder) | |
| for e in self.dropFirst(n) { | |
| if let insertionIndex = result.firstIndex(where: { areInIncreasingOrder(e, $0) }) { | |
| result.insert(e, at: insertionIndex) | |
| result.removeLast() | |
| } |
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
| package amal.global.amal | |
| import java.util.concurrent.atomic.AtomicReference | |
| import kotlin.concurrent.thread | |
| class Promise<T> private constructor(state: State<T>) { | |
| data class Callback<T>( | |
| val onFulfilled: (T) -> Unit, | |
| val onRejected: (kotlin.Error) -> Unit |
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 | |
| public enum Method: String { | |
| case GET | |
| case POST | |
| case PUT | |
| case PATCH | |
| case DELETE | |
| } |
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 Sequence where Element: Equatable { | |
| func allElementsEqual() -> Bool { | |
| var iterator = makeIterator() | |
| guard let first = iterator.next() else { return true } | |
| while let next = iterator.next() { | |
| if first != next { return false } | |
| } | |
| return true | |
| } | |
| } |
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 LineIterator: IteratorProtocol { | |
| let scanner: Scanner | |
| init(string: String) { | |
| scanner = Scanner(string: string) | |
| scanner.charactersToBeSkipped = .whitespaces | |
| } |
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
| tell application "Notes" | |
| move front note to folder "Archive" | |
| end tell |
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 CoreGraphics | |
| func / (lhs: Int, rhs: CGFloat) -> CGFloat { | |
| return CGFloat(lhs)/rhs | |
| } | |
| func / (lhs: CGFloat, rhs: Int) -> CGFloat { | |
| return lhs/CGFloat(rhs) | |
| } |