Skip to content

Instantly share code, notes, and snippets.

View phin's full-sized avatar

Séraphin Hochart phin

View GitHub Profile
@phin
phin / CustomOperatorNilCheck.swift
Created September 15, 2015 23:43
Swift - Coffescript "?" equivalent
import Cocoa
/*
CoffeeScript funfact: I have 2 values ​`a`​ and ​`b`​, and wanted a 3rd value ​`x`​ that is equal to ​`a`​ if it exists, otherwise is ​`b`​ if it exists, or is ​`undefined`​ if both are
sami [18:27]
I was able to do that with just ​`x = a ? b`
*/
infix operator ?| {}
func ?| <T>(left: T?, right: T?) -> T? {