Skip to content

Commit

Permalink
Add a new concatReducers variant
Browse files Browse the repository at this point in the history
  • Loading branch information
Charlotte Tortorella committed Apr 17, 2019
1 parent 2552814 commit c629219
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
27 changes: 17 additions & 10 deletions ReactiveReSwift.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -457,20 +457,23 @@
TargetAttributes = {
25DBCF361C30BF2B00D63A58 = {
CreatedOnToolsVersion = 7.2;
LastSwiftMigration = 1020;
};
25DBCF4D1C30C18D00D63A58 = {
CreatedOnToolsVersion = 7.2;
LastSwiftMigration = 1020;
};
25DBCF631C30C1AC00D63A58 = {
CreatedOnToolsVersion = 7.2;
LastSwiftMigration = 1020;
};
25DBCF7A1C30C4AA00D63A58 = {
CreatedOnToolsVersion = 7.2;
LastSwiftMigration = 0900;
LastSwiftMigration = 1020;
};
25DBCF861C30C4DB00D63A58 = {
CreatedOnToolsVersion = 7.2;
LastSwiftMigration = 0900;
LastSwiftMigration = 1020;
};
625E66821C1FF97E0027C288 = {
CreatedOnToolsVersion = 7.1.1;
Expand Down Expand Up @@ -744,6 +747,7 @@
PRODUCT_NAME = ReactiveReSwift;
SDKROOT = watchos;
SKIP_INSTALL = YES;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = 4;
};
name = Debug;
Expand All @@ -765,6 +769,7 @@
SDKROOT = watchos;
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = 4;
};
name = Release;
Expand All @@ -784,6 +789,7 @@
PRODUCT_NAME = ReactiveReSwift;
SDKROOT = appletvos;
SKIP_INSTALL = YES;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = 3;
};
name = Debug;
Expand All @@ -804,6 +810,7 @@
SDKROOT = appletvos;
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = 3;
};
name = Release;
Expand All @@ -816,6 +823,8 @@
PRODUCT_BUNDLE_IDENTIFIER = "reswift.github.io.ReSwift-tvOSTests";
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = appletvos;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = 3;
};
name = Debug;
};
Expand All @@ -828,6 +837,8 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = appletvos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = 3;
};
name = Release;
};
Expand All @@ -848,8 +859,7 @@
PRODUCT_NAME = ReactiveReSwift;
SDKROOT = macosx;
SKIP_INSTALL = YES;
SWIFT_SWIFT3_OBJC_INFERENCE = Off;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 5.0;
};
name = Debug;
};
Expand All @@ -870,8 +880,7 @@
PRODUCT_NAME = ReactiveReSwift;
SDKROOT = macosx;
SKIP_INSTALL = YES;
SWIFT_SWIFT3_OBJC_INFERENCE = Off;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 5.0;
};
name = Release;
};
Expand All @@ -886,8 +895,7 @@
PRODUCT_BUNDLE_IDENTIFIER = "reswift.github.io.ReSwift-MacTests";
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = macosx;
SWIFT_SWIFT3_OBJC_INFERENCE = Off;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 5.0;
};
name = Debug;
};
Expand All @@ -902,8 +910,7 @@
PRODUCT_BUNDLE_IDENTIFIER = "reswift.github.io.ReSwift-MacTests";
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = macosx;
SWIFT_SWIFT3_OBJC_INFERENCE = Off;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 5.0;
};
name = Release;
};
Expand Down
4 changes: 4 additions & 0 deletions Sources/CoreTypes/Reducer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import Foundation
public typealias Reducer<State> = (_ action: Action, _ state: State) -> State

public func concatReducers<State>(_ first: @escaping Reducer<State>, _ rest: Reducer<State>...) -> Reducer<State> {
return concatReducers(first: first, rest: rest)
}

public func concatReducers<State>(first: @escaping Reducer<State>, rest: [Reducer<State>]) -> Reducer<State> {
return { action, state in
rest.reduce(first(action, state)) { state, reducer in
reducer(action, state)
Expand Down
2 changes: 1 addition & 1 deletion Tests/ReducerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class ReducerTests: XCTestCase {
it combines the results from each individual reducer correctly
*/
func testCombinesReducerResults() {
let combinedReducer = concatReducers(increaseByOneReducer, increaseByTwoReducer)
let combinedReducer = concatReducers(first: increaseByOneReducer, rest: [increaseByTwoReducer])
let newState = combinedReducer(NoOpAction(), CounterState())

XCTAssertEqual(newState.count, 3)
Expand Down

0 comments on commit c629219

Please sign in to comment.