Skip to content

Instantly share code, notes, and snippets.

@Kametrixom
Last active September 3, 2015 07:01
Show Gist options
  • Save Kametrixom/8e9887defd210a737e72 to your computer and use it in GitHub Desktop.
Save Kametrixom/8e9887defd210a737e72 to your computer and use it in GitHub Desktop.
// This one is quite tricky
let returnN = getReturnN()
func availableToIntCollection<C: CollectionType where C.Generator.Element == Int>(c: C) {}
availableToIntCollection([1, 2, 3].lazy.map(returnN))
var a : Int { returnN (n: 3) }
var b : Int { return N(n: 3) }
@kostiakoval
Copy link

@noreturn Ahhh I was missing this one, nice!!!

@JessyCatterwaul
Copy link

It strikes me as strange that we can annotate a closure with @NoReturn when defining its type, but can't define such a closure directly; it must have a named function assigned to it instead. At least we can define nested functions:

func getReturnN() -> @noreturn (n: Int) -> Int {
    // Two n's are not needed; in fact, not even one is!
    // Only the parameter name in the return value matters.
    @noreturn func returnN(_: Int) -> Int {}
    return returnN
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment