Skip to content

Instantly share code, notes, and snippets.

View beccadax's full-sized avatar

Becca Royal-Gordon beccadax

View GitHub Profile
@beccadax
beccadax / raw.md
Last active July 2, 2018 20:07 — forked from erica/oldraw.md
print("""
<?xml version="1.0"?>
<catalog>
\(bookTuples.map(xmlForBookTuple).joined(separator: "")
)</catalog>
""")
typealias ChapterTuple = (heading: String)
typealias BookTuple = (id: String, author: String, title: String, genre: String, price: String, chapters: [ChapterTuple])
// Evaluates the given closure when two `Optional` instances are not `nil`,
// passing the unwrapped values as parameters. (Thanks, Mike Ash, Tim Vermeulen)
// Following the example of IEEE754 with NAN, any comparison involving
// .None is false
//
// See also: http://stackoverflow.com/questions/1565164/what-is-the-rationale-for-all-comparisons-returning-false-for-ieee754-nan-values
/// Returns nil if either parameter is nil, or a tuple of the parameters
/// otherwise.
func all<T, U>(_ first: T?, _ second: U?) -> (T, U)? {

Tuple-Based Compound Optional Binding

Introduction

This proposal enhances optional binding with a new, tuple-based syntax for

@beccadax
beccadax / with.md
Last active May 27, 2016 19:04 — forked from erica/with.md

Introducing with to the Standard Library

Introduction

This proposal introduces a with function to the standard library. This function

@beccadax
beccadax / Distance.swift
Last active August 29, 2015 14:25 — forked from fcanas/Distance.swift
Creating a Numeric Type : Distance
public struct Distance :NumericType {
public var value :Double
public init(_ value: Double) {
self.value = value
}
}
extension Distance :IntegerLiteralConvertible {
public init(integerLiteral: IntegerLiteralType) {
self.init(Double(integerLiteral))
extension String {
func split(separator:String) -> [String] {
return self.componentsSeparatedByString(separator)
}
}
extension Array {
func unpack() -> (T)? {
return count == 1 ? (self[0]) : nil
}