This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Version 2 of pagesFromData from Flattenin' Your Mappenin' | |
// http://robnapier.net/flatmap | |
// | |
import Foundation | |
infix operator >>== {} | |
func >>== <T,U>(x: T, f:T -> Result<U>) -> Result<U> { | |
return x.flatMap(f) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The Go-way (from http://robnapier.net/go-is-a-shop-built-jig) | |
func frobulate() -> NSError? { | |
if self.thingsToFrobulate > 0 { | |
if let error = logit(FrobulatingMessage) { | |
return error | |
} | |
if let error = self.removeOldest() { | |
return error | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Frobulate the ObjC way (from http://robnapier.net/go-is-a-shop-built-jig) | |
func frobulate(#error: NSErrorPointer) -> Bool { | |
if self.thingsToFrobulate > 0 { | |
if !logit(FrobulatingMessage, error: error) { | |
return false | |
} | |
if !self.removeOldest(error: error) { | |
return false | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-----BEGIN CERTIFICATE----- | |
MIIDHDCCAm6gAwIBAgIJAJzp0JfeVFY6MA0GCSqGSIb3DQEBBQUAMFkxCzAJBgNV | |
BAYTAkFVMRMwEQYDVQQIEwpTb21lLVN0YXRlMSEwHwYDVQQKExhJbnRlcm5ldCBX | |
aWRnaXRzIFB0eSBMdGQxEjAQBgNVBAMTCWxvY2FsaG9zdDAeFw0xNDEwMDMxODE3 | |
MzZaFw0xNTEwMDMxODE3MzZaMFkxCzAJBgNVBAYTAkFVMRMwEQYDVQQIEwpTb21l | |
LVN0YXRlMSEwHwYDVQQKExhJbnRlcm5ldCBXaWRnaXRzIFB0eSBMdGQxEjAQBgNV | |
BAMTCWxvY2FsaG9zdDCBtTANBgkqhkiG9w0BAQEFAAOBowAwgZ8CgZcNdHU/8upi | |
8hRasgwlUXb6m/sOnVq3pKxZfnaehJCKDlEfkJqq91maQbDNflxd41J+3r6En2x/ | |
eKJUvPJ/Lq5PsGTl127qYGElsgdcnJXpe7e2UZv/9OgJwq2sOtI+RwVpvs9ITPRU | |
caUPjmdKzyr4VwUEEj3fhBqnRSppz4pKtXK46ha+7UxWqU5pnPLLsssd+6/KIJzj |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct ZipExtendGenerator2<E0 : GeneratorType, E1 : GeneratorType> : GeneratorType { | |
typealias Element = (E0.Element?, E1.Element?) | |
var e0: E0 | |
var e1: E1 | |
init(_ e0: E0, _ e1: E1) { | |
self.e0 = e0 | |
self.e1 = e1 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// see also https://gist.github.com/griotspeak/8bb4c46611fc90d3043b | |
func findFirst<S: SequenceType>(seq: S, predicate: S.Generator.Element -> Bool) -> S.Generator.Element? { | |
for x in seq { | |
if predicate(x) { return x } | |
} | |
return nil | |
} | |
func not<T>(predicate: T -> Bool) -> (T -> Bool) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
typedef enum { | |
Sunday, | |
Monday, | |
Tuesday, | |
Wednesday, | |
Thursday, | |
Friday, | |
Saturday |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final class Box<T> { | |
let unbox: T | |
init(_ value: T) { self.unbox = value } | |
} | |
enum List<T> { | |
case Empty | |
case Cons(T, Box<List<T>>) // <- Converting this to Cons(Box<T>, Box<List<T>>) fixes it (thanks @CodeFi_) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Adds two linked lists together e.g. 1->2->3 + 4->5->6 = 5->7->9 | |
Each element is between 0 and 9 | |
*/ | |
final class Node: Printable, SequenceType { // Struct would be nicer here, but then we'd have to use boxing on next. | |
let data: Int | |
let next: Node? | |
init(data: Int, next: Node?) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Adds two linked lists together e.g. 1->2->3 + 4->5->6 = 5->7->9 | |
Each element is between 0 and 9 | |
This version uses a mutable data structure, which is trickier to use correctly, | |
but may work better for enormous lists. | |
It avoids recursion, which increases the number of vars required. | |
*/ | |
final class Node: Printable, SequenceType { // Struct would be nicer here, but then we'd have to use boxing on next. | |
var data: Int |