Last active
December 6, 2015 06:27
-
-
Save JessyCatterwaul/f1b9793cdab18b23ece1 to your computer and use it in GitHub Desktop.
catterwaul.com/=================Able
This file contains 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) | |
} | |
/// Used to implement Equatable using 5 properties | |
/// | |
///- ToDo: Add ability to use @noescape for the properties, to the language. | |
/// | |
///- Parameter right: term for the right side of the == | |
///- Parameter property📦: properties to equate using • operator | |
/// | |
///- Returns: whether all properties are equal | |
/// | |
///- Experiment: | |
/// - 🔗: Stuff that's "linked" together in a tuple | |
/// - 📦: Suffix for grouped stuff, usually a tuple. Acts like a tiny namespace. | |
func == <Any, | |
Property1: Equatable, | |
Property2: Equatable, | |
Property3: Equatable, | |
Property4: Equatable, | |
Property5: Equatable | |
>( | |
left: Any, | |
right🔗property📦: (right: Any, | |
Any -> Property1, | |
Any -> Property2, | |
Any -> Property3, | |
Any -> Property4, | |
Any -> Property5 | |
) | |
) -> Bool { | |
let right = right🔗property📦.right, | |
property📦 = right🔗property📦 | |
return left•property📦.1 == right•property📦.1 | |
&& left•property📦.2 == right•property📦.2 | |
&& left•property📦.3 == right•property📦.3 | |
&& left•property📦.4 == right•property📦.4 | |
&& left•property📦.5 == right•property📦.5 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment