Advertisement
Guest User

Untitled

a guest
Mar 29th, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. infix operator ??? : TernaryPrecedence
  2. infix operator ||| : AdditionPrecedence
  3.  
  4. func ???(input: String?, valuesBlock: ((String?) -> String)) -> String {
  5. return valuesBlock(input)
  6. }
  7.  
  8. func |||(ifNotNil: String, ifNil: String) -> ((String?) -> String) {
  9. return { (input: String?) -> String in
  10. if let _ = input {
  11. return ifNotNil
  12. } else {
  13. return ifNil
  14. }
  15. }
  16. }
  17.  
  18. var anotherOptionalValue: String? = nil
  19.  
  20. let notNil = anotherOptionalValue ??? valueIfNotNil ||| valueIfNil
  21. print("notNil: \(notNil)")
  22.  
  23. anotherOptionalValue = "string"
  24.  
  25. let yeahItsNil = anotherOptionalValue ??? valueIfNotNil ||| valueIfNil
  26. print("yeahItsNil: \(yeahItsNil)")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement