Skip to content

Commit

Permalink
Merge pull request #10 from RuiAAPeres/Swift3
Browse files Browse the repository at this point in the history
Swift3 (Xcode8 GM) fixes
  • Loading branch information
RuiAAPeres authored Sep 22, 2016
2 parents 05ce65f + 74b14c1 commit f2632f4
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
language: objective-c
osx_image: xcode7.3
osx_image: xcode8
script:
- set -o pipefail
- xcodebuild test -scheme OptionalExtensions-Mac | xcpretty -c
Expand Down
15 changes: 15 additions & 0 deletions OptionalExtensions.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -346,18 +346,23 @@
TargetAttributes = {
7DA0535A1C3DC5F3001F27B2 = {
CreatedOnToolsVersion = 7.2;
LastSwiftMigration = 0800;
};
7DA0536A1C3DC675001F27B2 = {
CreatedOnToolsVersion = 7.2;
LastSwiftMigration = 0800;
};
C7263FBB1C3C6BB200F402F9 = {
CreatedOnToolsVersion = 7.2;
LastSwiftMigration = 0800;
};
C7263FC91C3C6C9E00F402F9 = {
CreatedOnToolsVersion = 7.2;
LastSwiftMigration = 0800;
};
C7263FD71C3C6D1000F402F9 = {
CreatedOnToolsVersion = 7.2;
LastSwiftMigration = 0800;
};
C7EC1DC31C34503A00BA1261 = {
CreatedOnToolsVersion = 7.2;
Expand Down Expand Up @@ -532,6 +537,7 @@
PRODUCT_BUNDLE_IDENTIFIER = "rp.OptionalExtensions-Mac-Tests";
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = macosx;
SWIFT_VERSION = 3.0;
};
name = Debug;
};
Expand All @@ -546,6 +552,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = macosx;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 3.0;
};
name = Release;
};
Expand All @@ -557,6 +564,7 @@
PRODUCT_BUNDLE_IDENTIFIER = "rp.OptionalExtensions-tvOS-Tests";
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = appletvos;
SWIFT_VERSION = 3.0;
TARGETED_DEVICE_FAMILY = 3;
TVOS_DEPLOYMENT_TARGET = 9.1;
};
Expand All @@ -571,6 +579,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = appletvos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 3.0;
TARGETED_DEVICE_FAMILY = 3;
TVOS_DEPLOYMENT_TARGET = 9.1;
};
Expand All @@ -591,6 +600,7 @@
PRODUCT_NAME = OptionalExtensions;
SDKROOT = watchos;
SKIP_INSTALL = YES;
SWIFT_VERSION = 3.0;
TARGETED_DEVICE_FAMILY = 4;
WATCHOS_DEPLOYMENT_TARGET = 2.0;
};
Expand All @@ -612,6 +622,7 @@
SDKROOT = watchos;
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 3.0;
TARGETED_DEVICE_FAMILY = 4;
WATCHOS_DEPLOYMENT_TARGET = 2.0;
};
Expand All @@ -631,6 +642,7 @@
PRODUCT_NAME = OptionalExtensions;
SDKROOT = appletvos;
SKIP_INSTALL = YES;
SWIFT_VERSION = 3.0;
TARGETED_DEVICE_FAMILY = 3;
TVOS_DEPLOYMENT_TARGET = 9.0;
};
Expand All @@ -651,6 +663,7 @@
SDKROOT = appletvos;
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 3.0;
TARGETED_DEVICE_FAMILY = 3;
TVOS_DEPLOYMENT_TARGET = 9.0;
};
Expand All @@ -673,6 +686,7 @@
PRODUCT_NAME = OptionalExtensions;
SDKROOT = macosx;
SKIP_INSTALL = YES;
SWIFT_VERSION = 3.0;
};
name = Debug;
};
Expand All @@ -694,6 +708,7 @@
SDKROOT = macosx;
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 3.0;
};
name = Release;
};
Expand Down
30 changes: 10 additions & 20 deletions OptionalExtensions/Source/OptionalExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,52 +7,42 @@
//

public extension Optional {

func filter(_ predicate: @noescape (Wrapped) -> Bool) -> Optional {

func filter(_ predicate: (Wrapped) -> Bool) -> Optional {
return map(predicate) == .some(true) ? self : .none
}

func mapNil(_ predicate: @noescape (Void) -> Wrapped) -> Optional {

func mapNil(_ predicate: (Void) -> Wrapped) -> Optional {
return self ?? .some(predicate())
}

func flatMapNil(_ predicate: @noescape (Void) -> Optional) -> Optional {


func flatMapNil(_ predicate: (Void) -> Optional) -> Optional {
return self ?? predicate()
}

func then(_ f: @noescape (Wrapped) -> Void) {

func then(_ f: (Wrapped) -> Void) {
if let wrapped = self { f(wrapped) }
}


func maybe<U>(_ defaultValue: U, f: @noescape (Wrapped) -> U) -> U {


func maybe<U>(_ defaultValue: U, f: (Wrapped) -> U) -> U {
return map(f) ?? defaultValue
}

func onSome(_ f: @noescape (Wrapped) -> Void) -> Optional {

func onSome(_ f: (Wrapped) -> Void) -> Optional {
then(f)
return self
}

func onNone(_ f: @noescape (Void) -> Void) -> Optional {

func onNone(_ f: (Void) -> Void) -> Optional {
if isNone { f() }
return self
}

var isSome: Bool {

return self != nil
}

var isNone: Bool {

var isNone: Bool {
return !isSome
}
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<a href="https://travis-ci.org/RuiAAPeres/OptionalExtensions"><img src="https://travis-ci.org/RuiAAPeres/OptionalExtensions.svg?branch=master"></a>
<a href="https://github.com/Carthage/Carthage"><img src="https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat"></a>
[![CocoaPods](https://img.shields.io/cocoapods/v/OptionalExtensions.svg)](https://cocoapods.org/)
[![Swift 3.0 ß6](https://img.shields.io/badge/Swift-3.0-orange.svg?style=flat)](https://developer.apple.com/swift/)
[![Swift 3.0](https://img.shields.io/badge/Swift-3.0-orange.svg?style=flat)](https://developer.apple.com/swift/)
[![License MIT](https://img.shields.io/badge/License-MIT-lightgrey.svg?style=flat)](https://opensource.org/licenses/MIT)
![](https://camo.githubusercontent.com/410f44c161ebf367eacb1fcce9121e336e211bc6/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f506c6174666f726d2d696f732532302537432532306f737825323025374325323077617463686f7325323025374325323074766f732d6c69676874677265792e7376673f7374796c653d666c6174)

Expand Down

0 comments on commit f2632f4

Please sign in to comment.