[O] Implement obj.apply {} like Kotlin

This commit is contained in:
Hykilpikonna
2021-01-17 16:34:20 -05:00
parent 7e4dc51da8
commit 2c5f28c97b
3 changed files with 22 additions and 5 deletions
+14
View File
@@ -77,3 +77,17 @@ extension TimeInterval
else { return "\(seconds)s" }
}
}
/// Apply like Kotlin
protocol HasApply {}
extension HasApply
{
@discardableResult
func apply(_ c: (Self) -> ()) -> Self
{
c(self)
return self
}
}
extension Alarm: HasApply {}
extension Alarms: HasApply {}