GitXplorerGitXplorer
w

swift-undefined

public
80 stars
5 forks
0 issues

Commits

List of commits on branch master.
Unverified
414e3f4b2837e6a3825053081f9133d0b23798f4

type argument

committed 5 years ago
Unverified
60e668de5a0355b940937187c51371a41669383b

modernise

committed 5 years ago
Unverified
63e02107684750f787da6bf22899e1e22dffe4ff

add SwiftPM file

wweissi committed 8 years ago
Unverified
8d945554339045611d55c7b3e857f8984ae6b34f

updated for Swift 3

wweissi committed 8 years ago
Unverified
2d8e1d155f9428885ad1820611be6f5b8ac7dde9

Added a podspec.

nneonichu committed 10 years ago
Unverified
e413b00149bfcbdd27dd26f8a0b68e5b82d4b75a

make undefined public (as spotted in @neonichu's branch)

wweissi committed 9 years ago

README

The README file for this repository.

undefined for Swift

Micro frameworks are popular now, so I'll go nano framework :-). This is all the code:

/**
 * `undefined()` pretends to be able to produce a value of any type `T` which can
 * be very useful whilst writing a program. It happens that you need a value
 * (which can be a function as well) of a certain type but you can't produce it
 * just yet. However, you can always temporarily replace it by `undefined()`.
 *
 * Inspired by Haskell's
 * [undefined](http://hackage.haskell.org/package/base-4.7.0.2/docs/Prelude.html#v:undefined).
 *
 * Invoking `undefined()` will crash your program.
 *
 * Some examples:
 *
 *  - `let x : String = undefined()`
 *  - `let f : String -> Int? = undefined("string to optional int function")`
 *  - `return undefined() /* in any function */`
 *  - `let x : String = (undefined() as Int -> String)(42)`
 *  - ...
 *
 * What a crash looks like:
 *
 * `fatal error: undefined: main.swift, line 131`
 *
 */
public func undefined<T>(hint: String = "", file: StaticString = #file, line: UInt = #line) -> T {
    let message = hint == "" ? "" : ": \(hint)"
    fatalError("undefined \(T.self)\(message)", file:file, line:line)
}

More information

See my slides about undefined() from my Further Leveraging the Type System talk at Swift Summit 2015.