Skip to content

Commit f417c11

Browse files
committed
feat(FunctionalBuilder): API improvements
Added `set` method to a CallableBlock type
1 parent a0ce718 commit f417c11

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

Sources/FunctionalBuilder/Builder.swift

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import FunctionalConfigurator
22
import FunctionalKeyPath
3+
import FunctionalModification
34

45
@dynamicMemberLookup
56
public struct Builder<Base> {
@@ -129,7 +130,11 @@ extension Builder {
129130
Builder(
130131
_block.builder._initialValue,
131132
_block.builder._configurator.appendingConfiguration { base in
132-
_block.keyPath.embed(value(), in: base)
133+
if condition {
134+
return _block.keyPath.embed(value(), in: base)
135+
} else {
136+
return base
137+
}
133138
}
134139
)
135140
}
@@ -143,6 +148,18 @@ extension Builder {
143148
)
144149
}
145150

151+
public func set(_ transform: @escaping (inout Value) -> Void) -> Builder {
152+
Builder(
153+
_block.builder._initialValue,
154+
_block.builder._configurator.appendingConfiguration { base in
155+
_block.keyPath.embed(
156+
modification(of: _block.keyPath.extract(from: base), with: transform),
157+
in: base
158+
)
159+
}
160+
)
161+
}
162+
146163
public subscript<LocalValue>(
147164
dynamicMember keyPath: WritableKeyPath<Value, LocalValue>
148165
) -> CallableBlock<LocalValue> {

0 commit comments

Comments
 (0)