Skip to content
This repository has been archived by the owner on Jul 3, 2022. It is now read-only.

BrightFutures 2.0 #51

Merged
merged 63 commits into from
Jun 27, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
5f07f70
Added Cartfile
nvh May 12, 2015
223fab5
carthage bootstrap
nvh May 12, 2015
55861e5
Added frameworks to project
nvh May 12, 2015
36c398b
Added NSError to all type signatures of Result
nvh May 12, 2015
f36b849
Replaced all initializations of Result with the constructor in Result…
nvh May 12, 2015
785b85e
Unboxing errors everywhere
nvh May 12, 2015
cd2c31f
rewriting flatten and sequence
nvh May 12, 2015
41a8459
Removing recover
nvh May 12, 2015
1989958
Commenting out flatMap for futures
nvh May 12, 2015
252761d
Added helper extension for Result to ResultTest
nvh May 12, 2015
e6faea9
Rewriting isSuccess and isFailure with Result.analysis
nvh May 12, 2015
ab81d13
Replaced a lot of switch statements with Result.analysis
nvh May 12, 2015
4f2a7ff
Moved free functions to FutureUtils
nvh May 13, 2015
1f7c8eb
Updated flatMapFuture tests
nvh May 13, 2015
901ce01
Re-enabled recover tests
nvh May 13, 2015
0ee93b9
Update Result to 0.4.2
nvh May 13, 2015
8f2f87c
Merge branch 'pr/49' into 2.0-development
Thomvis May 14, 2015
eb50115
added Carthage dependencies as submodules
Thomvis May 14, 2015
599011f
Added Result to dependencies. Spec currently does not lint because Re…
Thomvis May 14, 2015
85e0270
corrected build phases. Dependencies do not have to be copied into th…
Thomvis May 14, 2015
094b779
attempt for adding carthage bootstrap to CircleCI configuration
Thomvis May 14, 2015
ad6d2c0
Trying to fix CircleCI build by just building for mac
Thomvis May 14, 2015
a3b0c1b
refactoring to remove dependency on NSError, tests do not compile yet
Thomvis May 15, 2015
9335a5c
tests compile & succeed
Thomvis May 17, 2015
c2c7a44
carthage now also builds for iOS, added verbose option for debugging
Thomvis May 17, 2015
9924b55
removed unneeded get's
Thomvis May 19, 2015
58f4551
Implemented BrightFuturesError.External error instead of EitherError
Thomvis May 19, 2015
53468d7
Moved runCallbacks to didSet of result
Thomvis May 21, 2015
b8150e6
added tests for forceType(), found & fixed bug
Thomvis May 21, 2015
1539c4f
BrightFuturesError is now parametrized with the client error it can c…
Thomvis May 23, 2015
9cc73cf
Updated license header in Error.swift
Thomvis May 23, 2015
afb8a5d
renamed Error.swift to Errors.swift
Thomvis May 23, 2015
4ab48cf
changed order of files in project
Thomvis May 23, 2015
be808e9
Updated documentation
Thomvis May 23, 2015
8db49dd
promoteError and promoteValue now use the ImmediateExecutionContext
Thomvis May 23, 2015
0294e34
Improved test for recover, ensuring the recover case is not evaluated…
Thomvis May 23, 2015
fd8960a
added missing documentation, now at 100% coverage
Thomvis May 23, 2015
9d1eabe
Marked ImmediateExecutionContext's parameter as @noescape
Thomvis May 23, 2015
3188be1
fixes compiler crash in Release mode by properly boxing the external …
Thomvis May 30, 2015
8a32709
removed test scheme, not needed
Thomvis May 30, 2015
1bd5070
work in progress of the 2.0 migration guide
Thomvis May 30, 2015
2341837
added workspace, tweaked dependency set-up
Thomvis May 31, 2015
37f836b
Update README.md
Thomvis May 31, 2015
54ff87c
Update README.md
Thomvis May 31, 2015
c595505
updated podspec
Thomvis May 31, 2015
401c96e
added missing tests for Errors
Thomvis Jun 3, 2015
f3a710f
improved test code coverage
Thomvis Jun 3, 2015
0308be7
updated CircleCI config
Thomvis Jun 3, 2015
64a8e78
updated build configuration
Thomvis Jun 8, 2015
ebc0876
Merge branch 'master' into 2.0-development
Thomvis Jun 26, 2015
2462513
Added missing tests, == for BrightFuturesError
Thomvis Jun 26, 2015
805f2a0
added missing line of documentation
Thomvis Jun 26, 2015
821b96a
Added changelog for 2.0.0
Thomvis Jun 26, 2015
5f86a25
updated readme for release
Thomvis Jun 26, 2015
8f82df8
added details on test & documentation coverage
Thomvis Jun 26, 2015
6078cee
deleted accidentally checked-in coverage files
Thomvis Jun 26, 2015
2b483a4
added link to the diff from the migration guide
Thomvis Jun 26, 2015
0674861
Update Migration_2.0.md
Thomvis Jun 26, 2015
aa35596
removed warning from readme
Thomvis Jun 27, 2015
f6691db
updated examples in the readme, making sure they still compile
Thomvis Jun 27, 2015
1028f5d
added note on Swift 2.0 compatibility, created releases section
Thomvis Jun 27, 2015
7d92603
added the 1.0.1 release
Thomvis Jun 27, 2015
fa2dcfa
Bumped version & Result dependency
Thomvis Jun 27, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "Carthage/Checkouts/Result"]
path = Carthage/Checkouts/Result
url = https://github.com/antitypical/Result.git
4 changes: 3 additions & 1 deletion BrightFutures.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'BrightFutures'
s.version = '1.0.1'
s.version = '2.0.0'
s.license = 'MIT'
s.summary = 'A simple Futures & Promises library for iOS and OS X written in Swift'
s.homepage = 'https://github.com/Thomvis/BrightFutures'
Expand All @@ -13,5 +13,7 @@ Pod::Spec.new do |s|

s.source_files = 'BrightFutures/*.swift'

s.dependency 'Result', '~> 0.4.3'

s.requires_arc = true
end
92 changes: 67 additions & 25 deletions BrightFutures.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
</BuildActionEntry>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForRunning = "NO"
buildForProfiling = "NO"
buildForArchiving = "NO"
buildForAnalyzing = "YES">
buildForAnalyzing = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "E9D45B091AF00659000F6CA7"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
</BuildActionEntry>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForRunning = "NO"
buildForProfiling = "NO"
buildForArchiving = "NO"
buildForAnalyzing = "YES">
buildForAnalyzing = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "E9DF081F194470060083F7F2"
Expand Down

This file was deleted.

13 changes: 13 additions & 0 deletions BrightFutures.xcworkspace/contents.xcworkspacedata

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

65 changes: 65 additions & 0 deletions BrightFutures.xcworkspace/xcshareddata/BrightFutures.xccheckout
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDESourceControlProjectFavoriteDictionaryKey</key>
<false/>
<key>IDESourceControlProjectIdentifier</key>
<string>3A31C8B6-B0CD-4D79-9DFB-AE57C9B04C9F</string>
<key>IDESourceControlProjectName</key>
<string>BrightFutures</string>
<key>IDESourceControlProjectOriginsDictionary</key>
<dict>
<key>57C931977B7D2307CC013C2BD93F90CF7C676790</key>
<string>https://github.com/robrix/Box.git</string>
<key>93608FFF008CD82ADDFA850BB9C1630FA754586F</key>
<string>github.com:Thomvis/BrightFutures.git</string>
<key>956D2B21DD155C49504BB67697A67F7C5351A353</key>
<string>https://github.com/antitypical/Result.git</string>
</dict>
<key>IDESourceControlProjectPath</key>
<string>BrightFutures.xcworkspace</string>
<key>IDESourceControlProjectRelativeInstallPathDictionary</key>
<dict>
<key>57C931977B7D2307CC013C2BD93F90CF7C676790</key>
<string>..Carthage/Checkouts/Result/Carthage/Checkouts/Box</string>
<key>93608FFF008CD82ADDFA850BB9C1630FA754586F</key>
<string>..</string>
<key>956D2B21DD155C49504BB67697A67F7C5351A353</key>
<string>..Carthage/Checkouts/Result</string>
</dict>
<key>IDESourceControlProjectURL</key>
<string>github.com:Thomvis/BrightFutures.git</string>
<key>IDESourceControlProjectVersion</key>
<integer>111</integer>
<key>IDESourceControlProjectWCCIdentifier</key>
<string>93608FFF008CD82ADDFA850BB9C1630FA754586F</string>
<key>IDESourceControlProjectWCConfigurations</key>
<array>
<dict>
<key>IDESourceControlRepositoryExtensionIdentifierKey</key>
<string>public.vcs.git</string>
<key>IDESourceControlWCCIdentifierKey</key>
<string>57C931977B7D2307CC013C2BD93F90CF7C676790</string>
<key>IDESourceControlWCCName</key>
<string>Box</string>
</dict>
<dict>
<key>IDESourceControlRepositoryExtensionIdentifierKey</key>
<string>public.vcs.git</string>
<key>IDESourceControlWCCIdentifierKey</key>
<string>93608FFF008CD82ADDFA850BB9C1630FA754586F</string>
<key>IDESourceControlWCCName</key>
<string>BrightFutures</string>
</dict>
<dict>
<key>IDESourceControlRepositoryExtensionIdentifierKey</key>
<string>public.vcs.git</string>
<key>IDESourceControlWCCIdentifierKey</key>
<string>956D2B21DD155C49504BB67697A67F7C5351A353</string>
<key>IDESourceControlWCCName</key>
<string>Result</string>
</dict>
</array>
</dict>
</plist>
95 changes: 95 additions & 0 deletions BrightFutures/Errors.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
// The MIT License (MIT)
//
// Copyright (c) 2014 Thomas Visser
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

import Foundation
import Box

/// To be able to use a type as an error type with BrightFutures, it needs to conform
/// to this protocol.
public protocol ErrorType {
/// An NSError describing this error
var nsError: NSError { get }
}

/// Can be used as the value type of a `Future` or `Result` to indicate it can never fail.
/// This is guaranteed by the type system, because `NoError` has no possible values and thus cannot be created.
public enum NoError {}

/// Extends `NSError` to conform to `ErrorType`
extension NoError: ErrorType {

/// From `ErrorType`: an NSError describing this error.
/// Since `NoError` cannot be constructed, this property can also never be accessed.
public var nsError: NSError {
fatalError("Impossible to construct NoError")
}
}

/// An extension of `NSError` to make it conform to `ErrorType`
extension NSError: ErrorType {

/// From `ErrorType`: An NSError describing this error.
/// Will return `self`.
public var nsError: NSError {
return self
}
}

/// The name of the domain that will be used when returning `NSError` representations of `BrightFuturesError` instances
public let BrightFuturesErrorDomain = "nl.thomvis.BrightFutures"

/// An enum representing every possible error for errors returned by BrightFutures
/// A `BrightFuturesError` can also wrap an external error (e.g. coming from a user defined future)
/// in its `External` case. `BrightFuturesError` has the type of the external error as its generic parameter.
public enum BrightFuturesError<E: ErrorType>: ErrorType {

case NoSuchElement
case InvalidationTokenInvalidated
case External(Box<E>)

/// Constructs a BrightFutures.External with the given external error
public init(external: E) {
self = .External(Box(external))
}

/// From `ErrorType`: An NSError describing this error.
public var nsError: NSError {
switch self {
case .NoSuchElement:
return NSError(domain: BrightFuturesErrorDomain, code: 0, userInfo: nil)
case .InvalidationTokenInvalidated:
return NSError(domain: BrightFuturesErrorDomain, code: 1, userInfo: nil)
case .External(let boxedError):
return boxedError.value.nsError
}
}
}

/// Returns `true` if `left` and `right` are both of the same case ignoring .External associated value
public func ==<E: Equatable>(lhs: BrightFuturesError<E>, rhs: BrightFuturesError<E>) -> Bool {
switch (lhs, rhs) {
case (.NoSuchElement, .NoSuchElement): return true
case (.InvalidationTokenInvalidated, .InvalidationTokenInvalidated): return true
case (.External(let lhs), .External(let rhs)): return lhs == rhs
default: return false
}
}
3 changes: 2 additions & 1 deletion BrightFutures/ExecutionContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ import Foundation
/// By default, an execution context can be assumed to be asynchronous unless stated otherwise
public typealias ExecutionContext = (() -> ()) -> ()

public func ImmediateExecutionContext(task: () -> ()) {
/// Immediately executes the given task. No threading, no semaphores.
public func ImmediateExecutionContext(@noescape task: () -> ()) {
task()
}

Expand Down
Loading