Slide 1

Slide 1 text

share your code

Slide 2

Slide 2 text

share your code

Slide 3

Slide 3 text

Brian Gesiak
 @modocache

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

compelling code

Slide 6

Slide 6 text

1. Precise 2. Convenient

Slide 7

Slide 7 text

tradeoffs

Slide 8

Slide 8 text

1. Precise 2. Convenient

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

BananaKit

Slide 11

Slide 11 text

Series

Slide 12

Slide 12 text

Series Z


Slide 13

Slide 13 text

@interface Banana : NSObject /** Whether the banana is peeled. */ @property (readonly) BOOL peeled; /** Whether the banana is delicious. @warning Do not use before the banana is peeled. */ @property (readonly) BOOL delicious; @end

Slide 14

Slide 14 text

@interface Banana : NSObject /** Whether the banana is peeled. */ @property (readonly) BOOL peeled; /** Whether the banana is delicious. @warning Do not use before the banana is peeled. */ @property (readonly) BOOL delicious; @end

Slide 15

Slide 15 text

@interface Banana : NSObject /** Whether the banana is peeled. */ @property (readonly) BOOL peeled; /** Whether the banana is delicious. @warning Do not use before the banana is peeled. */ @property (readonly) BOOL delicious; @end

Slide 16

Slide 16 text

@interface Banana : NSObject /** Whether the banana is peeled. */ @property (readonly) BOOL peeled; /** Whether the banana is delicious. @warning Do not use before the banana is peeled. */ @property (readonly) BOOL delicious; @end

Slide 17

Slide 17 text

BKBanana *banana = [[BKBanana alloc] init]; if (banana.delicious) { // ... }

Slide 18

Slide 18 text

BKBanana *banana = [[BKBanana alloc] init]; if (banana.delicious) { // ... } Caught "NSInternalInconsistencyException" º

Slide 19

Slide 19 text

enum Banana { /** An unpeeled banana has no taste. */ case Unpeeled /** A peeled banana has a boolean to indicate whether it's delicious. */ case Peeled(delicious: Bool) }

Slide 20

Slide 20 text

enum Banana { /** An unpeeled banana has no taste. */ case Unpeeled /** A peeled banana has a boolean to indicate whether it's delicious. */ case Peeled(delicious: Bool) }

Slide 21

Slide 21 text

enum Banana { /** An unpeeled banana has no taste. */ case Unpeeled /** A peeled banana has a boolean to indicate whether it's delicious. */ case Peeled(delicious: Bool) }

Slide 22

Slide 22 text

let banana = Banana.Unpeeled switch banana { case .Unpeeled: // ... case .Peeled(let delicious): if (delicious) { // ... } }

Slide 23

Slide 23 text

let banana = Banana.Unpeeled switch banana { case .Unpeeled: // ... case .Peeled(let delicious): if (delicious) { // ... } }

Slide 24

Slide 24 text

let banana = Banana.Unpeeled switch banana { case .Unpeeled: // ... case .Peeled(let delicious): if (delicious) { // ... } }

Slide 25

Slide 25 text

Banana [[ if } let banana = Banana.Unpeeled switch banana { case .Unpeeled: // ... case .Peeled(let delicious): if (delicious) { // ... } }

Slide 26

Slide 26 text

Banana *banana = [[Banana alloc] init]; if (banana.delicious) { // ... } let switch case case } }

Slide 27

Slide 27 text

MonkeyDB

Slide 28

Slide 28 text

@interface MonkeyDB : NSObject /** Creates a database backed by the store at the given URL. */ - (instancetype)initWithURL:(NSURL *)url; /** Loads a monkey with the given name, or nil if one doesn't exist. */ - (Monkey *)monkeyWithName:(NSString *)name error:(NSError **)error; @end

Slide 29

Slide 29 text

@interface MonkeyDB : NSObject /** Creates a database backed by the store at the given URL. */ - (instancetype)initWithURL:(NSURL *)url; /** Loads a monkey with the given name, or nil if one doesn't exist. */ - (Monkey *)monkeyWithName:(NSString *)name error:(NSError **)error; @end

Slide 30

Slide 30 text

@interface MonkeyDB : NSObject /** Creates a database backed by the store at the given URL. */ - (instancetype)initWithURL:(NSURL *)url; /** Loads a monkey with the given name, or nil if one doesn't exist. */ - (Monkey *)monkeyWithName:(NSString *)name error:(NSError **)error; @end

Slide 31

Slide 31 text

@interface Tricycle : NSObject @property (readonly) NSString *brandName; @end

Slide 32

Slide 32 text

@interface MonkeyDB (Tricycles) /** Looks up whether the given monkey owns a tricycle. If the monkey owns one, returns the tricycle. If not, returns nil. If an error occurs, the error pointer will be populated. */ - (Tricycle *)tricycleForMonkey:(Monkey *)monkey error:(NSError **)error; @end

Slide 33

Slide 33 text

@interface MonkeyDB (Tricycles) /** Looks up whether the given monkey owns a tricycle. If the monkey owns one, returns the tricycle. If not, returns nil. If an error occurs, the error pointer will be populated. */ - (Tricycle *)tricycleForMonkey:(Monkey *)monkey error:(NSError **)error; @end

Slide 34

Slide 34 text

MonkeyDB .monkey(name: String)

Slide 35

Slide 35 text

MonkeyDB .monkey(name: String) MonkeyDB .tricycle(monkey: Monkey)

Slide 36

Slide 36 text

MonkeyDB .monkey(name: String) MonkeyDB .tricycle(monkey: Monkey) Tricycle.brandName

Slide 37

Slide 37 text

NSURL *url = [NSURL fileURLWithPath:@".monkeydb"]; MonkeyDB *database = [[MonkeyDB alloc] initWithURL:url]; NSError *monkeyError = nil; Monkey *monkey = [database monkeyWithName:@"Peepers" error:&monkeyError]; if (monkey == nil || monkeyError != nil) { // ...error handling. return nil; } NSError *tricycleError = nil; Tricycle *tricycle = [database tricycleForMonkey:monkey error:&tricycleError];

Slide 38

Slide 38 text

NSURL *url = [NSURL fileURLWithPath:@".monkeydb"]; MonkeyDB *database = [[MonkeyDB alloc] initWithURL:url]; NSError *monkeyError = nil; Monkey *monkey = [database monkeyWithName:@"Peepers" error:&monkeyError]; if (monkey == nil || monkeyError != nil) { // ...error handling. return nil; } NSError *tricycleError = nil; Tricycle *tricycle = [database tricycleForMonkey:monkey error:&tricycleError];

Slide 39

Slide 39 text

NSURL *url = [NSURL fileURLWithPath:@".monkeydb"]; MonkeyDB *database = [[MonkeyDB alloc] initWithURL:url]; NSError *monkeyError = nil; Monkey *monkey = [database monkeyWithName:@"Peepers" error:&monkeyError]; if (monkey == nil || monkeyError != nil) { // ...error handling. return nil; } NSError *tricycleError = nil; Tricycle *tricycle = [database tricycleForMonkey:monkey error:&tricycleError];

Slide 40

Slide 40 text

NSURL *url = [NSURL fileURLWithPath:@".monkeydb"]; MonkeyDB *database = [[MonkeyDB alloc] initWithURL:url]; NSError *monkeyError = nil; Monkey *monkey = [database monkeyWithName:@"Peepers" error:&monkeyError]; if (monkey == nil || monkeyError != nil) { // ...error handling. return nil; } NSError *tricycleError = nil; Tricycle *tricycle = [database tricycleForMonkey:monkey error:&tricycleError];

Slide 41

Slide 41 text

// ...error handling. return nil; } NSError *tricycleError = nil; Tricycle *tricycle = [database tricycleForMonkey:monkey error:&tricycleError]; if (tricycle == nil || tricycleError != nil) { // ...error handling. return nil; } return tricycle.brandName;

Slide 42

Slide 42 text

// ...error handling. return nil; } NSError *tricycleError = nil; Tricycle *tricycle = [database tricycleForMonkey:monkey error:&tricycleError]; if (tricycle == nil || tricycleError != nil) { // ...error handling. return nil; } return tricycle.brandName;

Slide 43

Slide 43 text

// ...error handling. return nil; } NSError *tricycleError = nil; Tricycle *tricycle = [database tricycleForMonkey:monkey error:&tricycleError]; if (tricycle == nil || tricycleError != nil) { // ...error handling. return nil; } return tricycle.brandName;

Slide 44

Slide 44 text

NSURL *url = [NSURL fileURLWithPath:@".monkeydb"]; MonkeyDB *database = [[MonkeyDB alloc] initWithURL:url]; Monkey *monkey = [database monkeyWithName:@"Peepers" error:nil]; Tricycle *tricycle = [database tricycleForMonkey:monkey error:nil]; return tricycle.brandName;

Slide 45

Slide 45 text

NSURL *url = [NSURL fileURLWithPath:@".monkeydb"]; MonkeyDB *database = [[MonkeyDB alloc] initWithURL:url]; Monkey *monkey = [database monkeyWithName:@"Peepers" error:nil]; Tricycle *tricycle = [database tricycleForMonkey:monkey error:nil]; return tricycle.brandName; Caught "NSInternalInconsisntencyException" º

Slide 46

Slide 46 text

NSURL *url = [NSURL fileURLWithPath:@".monkeydb"]; MonkeyDB *database = [[MonkeyDB alloc] initWithURL:url]; Monkey *monkey = [database monkeyWithName:@"Peepers" error:nil]; Tricycle *tricycle = [database tricycleForMonkey:monkey error:nil]; return tricycle.brandName; Thread 1: EXC_BAD_INSTRUCTION

Slide 47

Slide 47 text

if (brandName) {
 // ...
 }

Slide 48

Slide 48 text

/** The result of an operation that could have failed. */ enum Result { /** If the operation succeeded, the result has a value. */ case Success(SuccessType) /** If the operation failed, the result holds an error. */ case Failure(ErrorType) }

Slide 49

Slide 49 text

/** The result of an operation that could have failed. */ enum Result { /** If the operation succeeded, the result has a value. */ case Success(SuccessType) /** If the operation failed, the result holds an error. */ case Failure(ErrorType) }

Slide 50

Slide 50 text

/** The result of an operation that could have failed. */ enum Result { /** If the operation succeeded, the result has a value. */ case Success(SuccessType) /** If the operation failed, the result holds an error. */ case Failure(ErrorType) }

Slide 51

Slide 51 text

LlamaKit

Slide 52

Slide 52 text

LlamaKit github.com/LlamaKit

Slide 53

Slide 53 text

struct MonkeyDB { init(url: NSURL) func monkey(name: String) -> Result func tricycle(monkey: Monkey) -> Result }

Slide 54

Slide 54 text

struct MonkeyDB { init(url: NSURL) func monkey(name: String) -> Result func tricycle(monkey: Monkey) -> Result }

Slide 55

Slide 55 text

struct MonkeyDB { init(url: NSURL) func monkey(name: String) -> Result func tricycle(monkey: Monkey) -> Result }

Slide 56

Slide 56 text

let result = database.tricycle(monkey) return result.brandName

Slide 57

Slide 57 text

let result = database.tricycle(monkey) return result.brandName 'Result' does not have a member named 'brandName'

Slide 58

Slide 58 text

let monkeyResult = database.monkey(“Peepers") switch monkeyResult { case .Failure(let error): return .Failure(error) case .Success(let monkey): let tricycleResult = database.tricycle(monkey) switch tricycleResult { case .Failure(let error): return .Failure(error) case .Success(let tricycle): return .Success(tricycle.brandName) } }

Slide 59

Slide 59 text

let monkeyResult = database.monkey(“Peepers") switch monkeyResult { case .Failure(let error): return .Failure(error) case .Success(let monkey): let tricycleResult = database.tricycle(monkey) switch tricycleResult { case .Failure(let error): return .Failure(error) case .Success(let tricycle): return .Success(tricycle.brandName) } }

Slide 60

Slide 60 text

let monkeyResult = database.monkey(“Peepers") switch monkeyResult { case .Failure(let error): return .Failure(error) case .Success(let monkey): let tricycleResult = database.tricycle(monkey) switch tricycleResult { case .Failure(let error): return .Failure(error) case .Success(let tricycle): return .Success(tricycle.brandName) } }

Slide 61

Slide 61 text

let monkeyResult = database.monkey(“Peepers") switch monkeyResult { case .Failure(let error): return .Failure(error) case .Success(let monkey): let tricycleResult = database.tricycle(monkey) switch tricycleResult { case .Failure(let error): return .Failure(error) case .Success(let tricycle): return .Success(tricycle.brandName) } }

Slide 62

Slide 62 text

let monkeyResult = database.monkey(“Peepers") switch monkeyResult { case .Failure(let error): return .Failure(error) case .Success(let monkey): let tricycleResult = database.tricycle(monkey) switch tricycleResult { case .Failure(let error): return .Failure(error) case .Success(let tricycle): return .Success(tricycle.brandName) } }

Slide 63

Slide 63 text

1. Precise 2. Convenient

Slide 64

Slide 64 text

let monkeyResult = database.monkey(“Peepers") switch monkeyResult { case .Failure(let error): return .Failure(error) case .Success(let monkey): let tricycleResult = database.tricycle(monkey) switch tricycleResult { case .Failure(let error): return .Failure(error) case .Success(let tricycle): return .Success(tricycle.brandName) } }

Slide 65

Slide 65 text

MonkeyDB .monkey(name: return MonkeyDB .tricycle(monkey: return

Slide 66

Slide 66 text

MonkeyDB .monkey(name: return .Failure(NSError) MonkeyDB .tricycle(monkey: return .Success( Tricycle.brandName)

Slide 67

Slide 67 text

MonkeyDB .monkey(name: String) return .Failure(NSError) MonkeyDB .tricycle(monkey: return .Success( Tricycle.brandName)

Slide 68

Slide 68 text

MonkeyDB .monkey(name: String) return .Failure(NSError) MonkeyDB .tricycle(monkey: return .Success( Tricycle.brandName)

Slide 69

Slide 69 text

MonkeyDB .monkey(name: String) return .Failure(NSError) MonkeyDB .tricycle(monkey: Monkey) return .Success( Tricycle.brandName)

Slide 70

Slide 70 text

MonkeyDB .monkey(name: String) return .Failure(NSError) MonkeyDB .tricycle(monkey: Monkey) return .Success( Tricycle.brandName)

Slide 71

Slide 71 text

MonkeyDB .monkey(name: String) return .Failure(NSError) MonkeyDB .tricycle(monkey: Monkey) return .Success( Tricycle.brandName)

Slide 72

Slide 72 text

MonkeyDB .monkey(name: return MonkeyDB .tricycle(monkey: return

Slide 73

Slide 73 text

MonkeyDB .monkey(name: return MonkeyDB .tricycle(monkey: return

Slide 74

Slide 74 text

MonkeyDB .monkey(name: return MonkeyDB .tricycle(monkey: return

Slide 75

Slide 75 text

enum Result { func map(transform: SuccessType -> NewType) -> Result func flatMap( transform: SuccessType -> Result) -> Result }

Slide 76

Slide 76 text

let monkeyResult = database.monkey("Peepers") let tricycleResult = monkeyResult.flatMap { (monkey: Monkey) in return database.tricycle(monkey) } let brandNameResult = tricycleResult.map { (tricycle: Tricycle) in return tricycle.brandName } return brandNameResult

Slide 77

Slide 77 text

let monkeyResult = database.monkey("Peepers") let tricycleResult = monkeyResult.flatMap { (monkey: Monkey) in return database.tricycle(monkey) } let brandNameResult = tricycleResult.map { (tricycle: Tricycle) in return tricycle.brandName } return brandNameResult

Slide 78

Slide 78 text

let monkeyResult = database.monkey("Peepers") let tricycleResult = monkeyResult.flatMap { (monkey: Monkey) in return database.tricycle(monkey) } let brandNameResult = tricycleResult.map { (tricycle: Tricycle) in return tricycle.brandName } return brandNameResult

Slide 79

Slide 79 text

let monkeyResult = database.monkey("Peepers") let tricycleResult = monkeyResult.flatMap { (monkey: Monkey) in return database.tricycle(monkey) } let brandNameResult = tricycleResult.map { (tricycle: Tricycle) in return tricycle.brandName } return brandNameResult

Slide 80

Slide 80 text

let monkeyResult = database.monkey("Peepers") let tricycleResult = monkeyResult.flatMap { (monkey: Monkey) in return database.tricycle(monkey) } let brandNameResult = tricycleResult.map { (tricycle: Tricycle) in return tricycle.brandName } return brandNameResult

Slide 81

Slide 81 text

let monkeyResult = database.monkey("Peepers") let tricycleResult = monkeyResult.flatMap { (monkey: Monkey) in return database.tricycle(monkey) } let brandNameResult = tricycleResult.map { (tricycle: Tricycle) in return tricycle.brandName } return brandNameResult

Slide 82

Slide 82 text

let monkeyResult = database.monkey("Peepers") let tricycleResult = monkeyResult.flatMap { (monkey: Monkey) in return database.tricycle(monkey) } let brandNameResult = tricycleResult.map { (tricycle: Tricycle) in return tricycle.brandName } return brandNameResult

Slide 83

Slide 83 text

let monkeyResult = database.monkey("Peepers") let tricycleResult = monkeyResult.flatMap { (monkey: Monkey) in return database.tricycle(monkey) } let brandNameResult = tricycleResult.map { (tricycle: Tricycle) in return tricycle.brandName } return brandNameResult

Slide 84

Slide 84 text

let monkeyResult = database.monkey("Peepers") let tricycleResult = monkeyResult.flatMap { (monkey: Monkey) in return database.tricycle(monkey) } let brandNameResult = tricycleResult.map { (tricycle: Tricycle) in return tricycle.brandName } return brandNameResult

Slide 85

Slide 85 text

let monkeyResult = database.monkey("Peepers") let tricycleResult = monkeyResult.flatMap { (monkey: Monkey) in return database.tricycle(monkey) } let brandNameResult = tricycleResult.map { (tricycle: Tricycle) in return tricycle.brandName } return brandNameResult

Slide 86

Slide 86 text

let monkeyResult = database.monkey("Peepers") let tricycleResult = monkeyResult.flatMap { (monkey: Monkey) in return database.tricycle(monkey) } let brandNameResult = tricycleResult.map { (tricycle: Tricycle) in return tricycle.brandName } return brandNameResult

Slide 87

Slide 87 text

let monkeyResult = database.monkey("Peepers") let tricycleResult = monkeyResult.flatMap { (monkey: Monkey) in return database.tricycle(monkey) } let brandNameResult = tricycleResult.map { (tricycle: Tricycle) in return tricycle.brandName } return brandNameResult

Slide 88

Slide 88 text

let monkeyResult = database.monkey("Peepers") let tricycleResult = monkeyResult.flatMap { (monkey: Monkey) in return database.tricycle(monkey) } let brandNameResult = tricycleResult.map { (tricycle: Tricycle) in return tricycle.brandName } return brandNameResult

Slide 89

Slide 89 text

let monkeyResult = database.monkey("Peepers") let tricycleResult = monkeyResult.flatMap { (monkey: Monkey) in return database.tricycle(monkey) } let brandNameResult = tricycleResult.map { (tricycle: Tricycle) in return tricycle.brandName } return brandNameResult

Slide 90

Slide 90 text

let monkeyResult = database.monkey("Peepers") let tricycleResult = monkeyResult.flatMap { (monkey: Monkey) in return database.tricycle(monkey) } let brandNameResult = tricycleResult.map { (tricycle: Tricycle) in return tricycle.brandName } return brandNameResult

Slide 91

Slide 91 text

let monkeyResult = database.monkey("Peepers") let tricycleResult = monkeyResult.flatMap { (monkey: Monkey) in return database.tricycle(monkey) } let brandNameResult = tricycleResult.map { (tricycle: Tricycle) in return tricycle.brandName } return brandNameResult

Slide 92

Slide 92 text

let monkeyResult = database.monkey("Peepers") let tricycleResult = monkeyResult.flatMap { (monkey: Monkey) in return database.tricycle(monkey) } let brandNameResult = tricycleResult.map { (tricycle: Tricycle) in return tricycle.brandName } return brandNameResult

Slide 93

Slide 93 text

let monkeyResult = database.monkey("Peepers") let tricycleResult = monkeyResult.flatMap { (monkey: Monkey) in return database.tricycle(monkey) } let brandNameResult = tricycleResult.map { (tricycle: Tricycle) in return tricycle.brandName } return brandNameResult let tricycleResult = monkeyResult.flatMap { return database.tricycle($0) }

Slide 94

Slide 94 text

let monkeyResult = database.monkey("Peepers") let tricycleResult = monkeyResult.flatMap { (monkey: Monkey) in return database.tricycle(monkey) } let brandNameResult = tricycleResult.map { (tricycle: Tricycle) in return tricycle.brandName } return brandNameResult let tricycleResult = monkeyResult.flatMap { return database.tricycle($0) } let brandNameResult = tricycleResult.map { return $0.brandName }

Slide 95

Slide 95 text

let monkeyResult = database.monkey("Peepers") let tricycleResult = monkeyResult.flatMap { return database.tricycle($0) } let brandNameResult = tricycleResult.map { return $0.brandName } return brandNameResult

Slide 96

Slide 96 text

let monkeyResult = database.monkey("Peepers") let tricycleResult = monkeyResult.flatMap { return database.tricycle($0) } let brandNameResult = tricycleResult.map { return $0.brandName } return brandNameResult let brandNameResult = tricycleResult.map { $0.brandName } let tricycleResult = monkeyResult.flatMap { database.tricycle($0) }

Slide 97

Slide 97 text

return database.monkey("Peepers") .flatMap { database.tricycle($0) } .map { $0.brandName }

Slide 98

Slide 98 text

return database.monkey("Peepers") .flatMap { database.tricycle($0) } .map { $0.brandName }

Slide 99

Slide 99 text

return database.monkey("Peepers") .flatMap { database.tricycle($0) } .map { $0.brandName }

Slide 100

Slide 100 text

return database.monkey("Peepers") .flatMap { database.tricycle($0) } .map { $0.brandName }

Slide 101

Slide 101 text

No content

Slide 102

Slide 102 text

No content

Slide 103

Slide 103 text

No content

Slide 104

Slide 104 text

Gift

Slide 105

Slide 105 text

Gift https://github.com/modocache/Gift

Slide 106

Slide 106 text

let url = NSURL( fileURLWithPath: "/Users/modocache/Gift")! let latestCommitMessage = openRepository(url) .flatMap { $0.headReference } .flatMap { $0.commit } .flatMap { $0.message } switch latestCommitMessage { case .Success(let message): println(message) case .Failure(let error): println(error.localizedDescription) }

Slide 107

Slide 107 text

let url = NSURL( fileURLWithPath: "/Users/modocache/Gift")! let latestCommitMessage = openRepository(url) .flatMap { $0.headReference } .flatMap { $0.commit } .flatMap { $0.message } switch latestCommitMessage { case .Success(let message): println(message) case .Failure(let error): println(error.localizedDescription) }

Slide 108

Slide 108 text

let url = NSURL( fileURLWithPath: "/Users/modocache/Gift")! let latestCommitMessage = openRepository(url) .flatMap { $0.headReference } .flatMap { $0.commit } .flatMap { $0.message } switch latestCommitMessage { case .Success(let message): println(message) case .Failure(let error): println(error.localizedDescription) }

Slide 109

Slide 109 text

let url = NSURL( fileURLWithPath: "/Users/modocache/Gift")! let latestCommitMessage = openRepository(url) .flatMap { $0.headReference } .flatMap { $0.commit } .flatMap { $0.message } switch latestCommitMessage { case .Success(let message): println(message) case .Failure(let error): println(error.localizedDescription) }

Slide 110

Slide 110 text

let url = NSURL( fileURLWithPath: "/Users/modocache/Gift")! let latestCommitMessage = openRepository(url) .flatMap { $0.headReference } .flatMap { $0.commit } .flatMap { $0.message } switch latestCommitMessage { case .Success(let message): println(message) case .Failure(let error): println(error.localizedDescription) }

Slide 111

Slide 111 text

openRepository(url) .flatMap { $0.index } .flatMap { $0.add() } .flatMap { $0.writeTree() } .flatMap { $0.commit("This is bananas!") } git commit --all --message "this is bananas"

Slide 112

Slide 112 text

openRepository(url) .flatMap { $0.index } .flatMap { $0.add() } .flatMap { $0.writeTree() } .flatMap { $0.commit("This is bananas!") } git commit --all --message "this is bananas"

Slide 113

Slide 113 text

openRepository(url) .flatMap { $0.index } .flatMap { $0.add() } .flatMap { $0.writeTree() } .flatMap { $0.commit("This is bananas!") } git commit --all --message "this is bananas"

Slide 114

Slide 114 text

openRepository(url) .flatMap { $0.index } .flatMap { $0.add() } .flatMap { $0.writeTree() } .flatMap { $0.commit("This is bananas!") } git commit --all --message "this is bananas"

Slide 115

Slide 115 text

openRepository(url) .flatMap { $0.index } .flatMap { $0.add() } .flatMap { $0.writeTree() } .flatMap { $0.commit("This is bananas!") } git commit --all --message "this is bananas"

Slide 116

Slide 116 text

let entryCountResult = openRepository(url) .flatMap { $0.index } .map { $0.entryCount } git status --staged | wc -l

Slide 117

Slide 117 text

let entryCountResult = openRepository(url) .flatMap { $0.index } .map { $0.entryCount } git status --staged | wc -l

Slide 118

Slide 118 text

let entryCountResult = openRepository(url) .flatMap { $0.index } .map { $0.entryCount } git status --staged | wc -l

Slide 119

Slide 119 text

let entryCountResult = openRepository(url) .flatMap { $0.index } .map { $0.entryCount } git status --staged | wc -l

Slide 120

Slide 120 text

let entryCountResult = openRepository(url) .flatMap { $0.index } .map { $0.entryCount } git status --staged | wc -l

Slide 121

Slide 121 text

let entryCountResult = openRepository(url) .flatMap { $0.index } .map { $0.entryCount } git status --staged | wc -l

Slide 122

Slide 122 text

let entryCountResult = openRepository(url) .flatMap { $0.index } .map { $0.entryCount } git status --staged | wc -l

Slide 123

Slide 123 text

enum Result { func map(transform: SuccessType -> NewType) -> Result func flatMap( transform: SuccessType -> Result) -> Result }

Slide 124

Slide 124 text

enum Result { func map(transform: SuccessType -> NewType) -> Result func flatMap( transform: SuccessType -> Result) -> Result }

Slide 125

Slide 125 text

enum Result { func map(transform: SuccessType -> NewType) -> Result func flatMap( transform: SuccessType -> Result) -> Result }

Slide 126

Slide 126 text

enum Result { func map(transform: SuccessType -> NewType) -> Result func flatMap( transform: SuccessType -> Result) -> Result }

Slide 127

Slide 127 text

enum Result { func map(transform: SuccessType -> NewType) -> Result func flatMap( transform: SuccessType -> Result) -> Result }

Slide 128

Slide 128 text

enum Result { func map(transform: SuccessType -> NewType) -> Result func flatMap( transform: SuccessType -> Result) -> Result }

Slide 129

Slide 129 text

enum Result { func map(transform: SuccessType -> NewType) -> Result func flatMap( transform: SuccessType -> Result) -> Result }

Slide 130

Slide 130 text

let entryCountResult = openRepository(url) .flatMap { $0.index } .map { $0.entryCount } git status --staged | wc -l

Slide 131

Slide 131 text

tradeoff?

Slide 132

Slide 132 text

return database.monkey("Peepers") .flatMap { database.tricycle($0) } .map { $0.brandName }

Slide 133

Slide 133 text

1. Precise 2. Convenient

Slide 134

Slide 134 text

Thanks!

Slide 135

Slide 135 text

Thanks!

Slide 136

Slide 136 text

@modocache
 github.com/LlamaKit/LlamaKit github.com/modocache/Gift github.com/SwiftGit2/SwiftGit2