Skip to content

Commit 35f0fe2

Browse files
committed
feat: Combining API for Configurator & Builder improved
1 parent 5f20d0d commit 35f0fe2

File tree

4 files changed

+33
-3
lines changed

4 files changed

+33
-3
lines changed

Sources/FunctionalBuilder/Builder.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,20 @@ public struct Builder<Base> {
4747
reinforce { base in transform(&base, t0, t1, t2) }
4848
}
4949

50+
public func combined(with builder: Builder) -> Builder {
51+
Builder(
52+
_initialValue,
53+
_configurator.combined(with: builder._configurator)
54+
)
55+
}
56+
57+
public func combined(with configurator: Configurator<Base>) -> Builder {
58+
Builder(
59+
_initialValue,
60+
_configurator.combined(with: configurator)
61+
)
62+
}
63+
5064
/// Creates a new instance of builder with initial value
5165
public init(_ initialValue: @escaping @autoclosure () -> Base) {
5266
self.init(

Sources/FunctionalClosures/DataSource.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ public class DataSource<Input, Output> {
3535
}
3636
}
3737

38-
3938
/// A wrapper for clusure-based interaction between objects
4039
///
4140
/// Provides a public API to set internal closure-based datasource with a functional API

Sources/FunctionalConfigurator/Configurator.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,12 @@ public struct Configurator<Base> {
4242
}
4343
}
4444

45+
public func combined(with configurator: Configurator) -> Configurator {
46+
appendingConfiguration(configurator._configure)
47+
}
48+
4549
/// Appends modification of a new configurator to stored configuration
50+
@available(*, deprecated, message: "Use `combined(with:) instead`")
4651
public func appending(_ configurator: Configurator) -> Configurator {
4752
appendingConfiguration(configurator._configure)
4853
}
@@ -153,7 +158,7 @@ extension Configurator {
153158
) -> Configurator {
154159
_block.configurator.appendingConfiguration { base in
155160
_block.keyPath.embed(
156-
modification(of: _block.keyPath.extract(from: base), with: configuration),
161+
_modification(of: _block.keyPath.extract(from: base), with: configuration),
157162
in: base
158163
)
159164
}
@@ -200,7 +205,7 @@ extension Configurator {
200205
) -> Configurator where Value: AnyObject {
201206
configurator.appendingConfiguration { base in
202207
keyPath.embed(
203-
modification(of: keyPath.extract(from: base), with: configuration),
208+
_modification(of: keyPath.extract(from: base), with: configuration),
204209
in: base
205210
)
206211
}

Sources/FunctionalConfigurator/Modification.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
///
33
/// Returns a new instance for value types
44
/// Returns modified reference for reference types
5+
@available(*, deprecated, message: """
6+
This function will be made internal in `1.0.0` release, implement `CustomConfigurable` protocol for your object and use instance method instead
7+
""")
58
@inlinable
69
public func modification<Object>(
710
of object: Object,
@@ -10,3 +13,12 @@ public func modification<Object>(
1013
return Configurator(config: configuration)
1114
.configured(object)
1215
}
16+
17+
18+
@inlinable
19+
internal func _modification<Object>(
20+
of object: Object,
21+
with configuration: (Configurator<Object>) -> Configurator<Object>
22+
) -> Object {
23+
return Configurator(config: configuration).configured(object)
24+
}

0 commit comments

Comments
 (0)