Nano framework which defines Haskell's undefined in Swift.

Overview

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.

You might also like...
Your SwiftUI custom slider is crap. Here's mine, which is also crap, but it's my crap

Fuck your custom slider It doesn't work. Sure, it looks great, with gradients, and multiple thumbs, but really, it's useless. No more paying for a sub

A SwiftUI component which handles logging in with Apple to Firebase
A SwiftUI component which handles logging in with Apple to Firebase

Login with Apple Firebase SwiftUI I made this SwiftUI component to handle logging in with Apple to Firebase. Demo Gif Usage in SwiftUI struct ContentV

Reading List is an iOS app for iPhone and iPad which helps users track and catalog the books they read
Reading List is an iOS app for iPhone and iPad which helps users track and catalog the books they read

Reading List Reading List is an iOS app for iPhone and iPad which helps users track and catalog the books they read. Reading List v2 As of version 2.0

 Quotes App - quotes browsing app which is built with Quotable Free API completely in UIKit
Quotes App - quotes browsing app which is built with Quotable Free API completely in UIKit

Quotes App is quotes browsing app which is built with Quotable Free API completely in UIKit

Bookworm - Track which books you’ve read and what you thought of them
Bookworm - Track which books you’ve read and what you thought of them

Bookworm Description: Bookworm is an app I built while following 100 Days of Swi

This app is a native client for openHAB which allows easy access to your sitemaps

openHAB client for iOS Introduction This app is a native client for openHAB which allows easy access to your sitemaps. Beta releases are available on

An open-source app which can help you record income and expense
An open-source app which can help you record income and expense

MoneyPlus An open-source app which can help you record income and expense. 中文 0x00 Introduction First quick devolopment in iOS using Swift programmati

LeitnerBox is an iOS application which help language learners to memorize words faster.
LeitnerBox is an iOS application which help language learners to memorize words faster.

Leitner-Box Leitner-Box is an iOS application to memorize word forever. Features Memorize words and phrases. Ability to export the database and import

WeHobby is an IOS application which aims to facilitate the discovery of new hobbies while creating links between users.

🇬🇧 WeHobby (EN) WeHobby is an IOS application which aims to facilitate the discovery of new hobbies while creating links between users. The issues t

Owner
Johannes Weiss
Johannes Weiss
A simple and lightweight Swift package which provides a SwiftUI view for interactive geo coordinates input!

LocationPicker for SwiftUI LocationPicker for SwiftUI is a very simple and lightweight Swift package which provides you a SwiftUI view for interactive

Alessio Rubicini 17 Dec 7, 2022
An example to-do list app using SwiftUI which is introduced in WWDC19

SwiftUITodo SwiftUITodo is an example to-do list application using SwiftUI which is first introduced in WWDC19 keynote. Requirements Xcode 11 Beta Swi

Suyeol Jeon 701 Dec 23, 2022
KHabit an open source, pure and minimalistic app which helps you maintain productive habits, and nothing more.

an open source, pure and minimalistic app which helps you maintain productive habits, and nothing more. The app is completely open source, it does not contain in-app or ads, and does not track the user in any way.

Stefano Bertoli 42 Dec 17, 2022
an open source, pure and minimalistic app which helps you maintain productive habits, and nothing more.

KHabit an open source, pure and minimalistic app which helps you maintain productive habits, and nothing more. The app is completely open source, it d

Stefano Bertoli 17 May 5, 2021
Quotes App is quotes browsing app which is built with Quotable Free API completely in SwiftUI.

Quotes App is quotes browsing app which is built with Quotable Free API completely in SwiftUI. You can watch the whole journey of building this

Dheeraj Kumar Sharma 32 Nov 22, 2022
A simple todo app which aims to demonstrate some new concepts from SwiftUI 3

TodoAppSwiftUI3 A simple todo app which aims to demonstrate some new concepts from SwiftUI 3 Description This is a simple todo app built to demonstrat

Roman Luzgin 50 Nov 1, 2022
App which lets two people share their social media details by simply putting one phone on top of the other ("tapping"). Currently in development by Nikita Mounier.

Tap It Tap It enables two people to seamlessly share their social media information (e.g. Instagram, Snapchat, phone number) by simply placing one scr

Nikita Mounier 24 Oct 21, 2022
Implemented MVVM-C (Coordinator) architecture pattern for the project. Which is satisfying SOLID principles altogether. Protocol oriented development has been followed.

BreakingBad BreakingBad API doc Implemented MVVM-C (Coordinator) architecture pattern for the project. Which is satisfying SOLID principples altogethe

Dhruvik Rao 2 Mar 10, 2022
iOS App by which the user can display a list of characters from the Harry Potter Movies.

iOS App by which the user can display a list of characters from the Harry Potter Movies. They can display a list of all characters, students, staff or view characters by house.

Matthew Hollyhead 0 Nov 7, 2021
A mobile application project designed for everybody which provides the easiest way to make searchs for public services

A mobile application project designed for everybody which provides the easiest way to make searchs for public services

null 0 Nov 23, 2021