-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTypeHelper.swift
More file actions
36 lines (29 loc) · 1.05 KB
/
Copy pathTypeHelper.swift
File metadata and controls
36 lines (29 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
//
// TypeHelper.swift
// ReSwift
//
// Created by Benjamin Encz on 11/27/15.
// Copyright © 2015 DigiTales. All rights reserved.
//
import Foundation
import ReSwift
func withSpecificTypes<SpecificStateType: StateType, Action>(
action: Action,
state genericStateType: StateType?,
@noescape function: (action: Action, state: SpecificStateType?) -> StateType
) -> StateType {
guard let genericStateType = genericStateType else {
return function(action: action, state: nil)
}
guard let specificStateType = genericStateType as? SpecificStateType else {
return genericStateType
}
let newState = function(action: action, state: specificStateType)
if let newLoopState = newState as? LoopStateType<SpecificStateType> {
return newLoopState
}
if let newState = newState as? SpecificStateType {
return LoopStateType(model: newState, effect: nil)
}
return genericStateType
}