Skip to content

Instantly share code, notes, and snippets.

@JessyCatterwaul
Last active December 12, 2015 18:15
Show Gist options
  • Save JessyCatterwaul/5be724763532bc085e43 to your computer and use it in GitHub Desktop.
Save JessyCatterwaul/5be724763532bc085e43 to your computer and use it in GitHub Desktop.
public struct CoreError: ErrorType {
public init(
_ reason: String,
_ context: String = __FILE__
) {
self.reason = reason
self.context = context
}
let
reason: String,
context: String
}
/// 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 properties: properties to equate using • operator
///
///- Returns: whether all properties are equal
///
///- Experiment:
/// - 🔗: Stuff that's "linked" together in a tuple
func == <Any,
Property1: Equatable,
Property2: Equatable,
Property3: Equatable,
Property4: Equatable,
Property5: Equatable
>(
left: Any,
right🔗properties: (right: Any,
Any -> Property1,
Any -> Property2,
Any -> Property3,
Any -> Property4,
Any -> Property5
)
) -> Bool {
let right = right🔗properties.right,
properties = right🔗properties
return left•properties.1 == right•properties.1
&& left•properties.2 == right•properties.2
&& left•properties.3 == right•properties.3
&& left•properties.4 == right•properties.4
&& left•properties.5 == right•properties.5
}
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)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment