Skip to content

Instantly share code, notes, and snippets.

Avatar

Becca Royal-Gordon beccadax

View GitHub Profile
View raw.md
View gist:daa9e2112f9c6aa4a5720cf5e81febb6
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])
View optionalequality.swift
// 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)? {
View tuple-compound-if-let.md

Tuple-Based Compound Optional Binding

Introduction

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

View 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 Aug 29, 2015 — forked from fcanas/Distance.swift
Creating a Numeric Type : Distance
View Distance.swift
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))
View Stupid overloading tricks
extension String {
func split(separator:String) -> [String] {
return self.componentsSeparatedByString(separator)
}
}
extension Array {
func unpack() -> (T)? {
return count == 1 ? (self[0]) : nil
}