File tree Expand file tree Collapse file tree 2 files changed +34
-0
lines changed
Sources/FunctionalConfigurator
Tests/DeclarativeConfigurationTests Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -148,6 +148,17 @@ extension Configurator {
148148 }
149149 }
150150
151+ public func scope(
152+ _ configuration: @escaping ( Configurator < Value > ) -> Configurator < Value >
153+ ) -> Configurator {
154+ _block. configurator. appendingConfiguration { base in
155+ _block. keyPath. embed (
156+ modification ( of: _block. keyPath. extract ( from: base) , with: configuration) ,
157+ in: base
158+ )
159+ }
160+ }
161+
151162 public subscript< LocalValue> (
152163 dynamicMember keyPath: WritableKeyPath < Value , LocalValue >
153164 ) -> CallableBlock < LocalValue > {
Original file line number Diff line number Diff line change @@ -56,4 +56,27 @@ final class BuilderTests: XCTestCase {
5656
5757 XCTAssertEqual ( flag, false , " Reinforce transform wasn't called " )
5858 }
59+
60+ func testScope( ) {
61+ struct Container : BuilderProvider , Equatable {
62+ struct Content : Equatable {
63+ var a : Int = 0
64+ var b : Int = 0
65+ var c : Int = 0
66+ }
67+ var content : Content = . init( )
68+ }
69+
70+ let expected = Container ( content: . init( a: 1 , b: 2 , c: 3 ) )
71+ let initial = Container ( )
72+ let actual = initial. builder
73+ . content. scope { $0
74+ . a ( 1 )
75+ . b ( 2 )
76+ . c ( 3 )
77+ } . build ( )
78+
79+ XCTAssertNotEqual ( initial, expected)
80+ XCTAssertEqual ( actual, expected)
81+ }
5982}
You can’t perform that action at this time.
0 commit comments