Last active
December 14, 2015 20:18
-
-
Save JessyCatterwaul/cf7afb4819fe1a542712 to your computer and use it in GitHub Desktop.
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
infix operator • {precedence 255} | |
/// Used when you'd normally use the dot operator to get a property, | |
/// but you have to store that operation as a closure for whatever reason. | |
/// | |
///- Parameter instance: instance on which you'd normally use a dot | |
///- Parameter property: returns a Property when supplied with an instance | |
/// | |
///- Returns: the property | |
/// | |
///- Remark: Hold option, press 8 | |
/// | |
///- Note: Swift's "instance methods" are a lot like this. | |
/// They're really static methods that take an instance as their first parameter. | |
func •<Any, Property>( | |
instance: Any, | |
@noescape property: (of: Any) -> Property | |
) -> Property { | |
return property(of: instance) | |
} | |
public extension Dictionary { | |
// Splats init(dictionaryLiteral elements: (Key, Value)...) | |
public init<KeyValueSequence: SequenceType | |
where KeyValueSequence.Generator.Element == (Key, Value) | |
>(_ elements: KeyValueSequence) { | |
self.init() | |
for element in elements {self[element.0] = element.1} | |
} | |
public init<Sequence: SequenceType>( | |
_ sequence: Sequence, | |
_ key🔗value: Sequence.Generator.Element -> (Key, Value) | |
) { | |
self.init(sequence.map{$0•key🔗value}) | |
} | |
} | |
extension SequenceType { | |
func Dictionary<Key, Value>( | |
key🔗value: Generator.Element -> (Key, Value) | |
) -> Swift.Dictionary<Key, Value> { | |
return Swift.Dictionary(self, key🔗value) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment