-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathActionLens.swift
74 lines (66 loc) · 1.96 KB
/
ActionLens.swift
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
public struct ActionLens<AsyncAction, SyncAction> {
public typealias Action = EitherAction<AsyncAction, SyncAction>
let dispatchFunction: (Bool, Bool, [Action]) -> Void
public func callAsFunction<S: Sequence>(
serially: Bool = false,
collect: Bool = false,
actions: S
) where S.Element == Action {
dispatchFunction(serially, collect, .init(actions))
}
public func callAsFunction<S: Sequence>(
serially: Bool = false,
collect: Bool = false,
sync actions: S
) where S.Element == SyncAction {
dispatchFunction(serially, collect, [.sync(.init(actions))])
}
public func callAsFunction<S: Sequence>(
serially: Bool = false,
collect: Bool = false,
async actions: S
) where S.Element == AsyncAction {
dispatchFunction(serially, collect, [.async(.init(actions))])
}
}
public extension ActionLens where AsyncAction == Never, SyncAction == Void {
func callAsFunction() {
dispatchFunction(
false,
false,
[.sync([()])]
)
}
}
public extension ActionLens where AsyncAction == Void, SyncAction == Never {
func callAsFunction() {
dispatchFunction(
false,
false,
[.async([()])]
)
}
}
public extension ActionLens {
func callAsFunction(
serially: Bool = false,
collect: Bool = false,
actions: Action...
) {
callAsFunction(serially: serially, collect: collect, actions: actions)
}
func callAsFunction(
serially: Bool = false,
collect: Bool = false,
sync actions: SyncAction...
) {
callAsFunction(serially: serially, collect: collect, sync: actions)
}
func callAsFunction(
serially: Bool = false,
collect: Bool = false,
async actions: AsyncAction...
) {
callAsFunction(serially: serially, collect: collect, async: actions)
}
}