Skip to content

Commit

Permalink
style: Format places not handled by ci
Browse files Browse the repository at this point in the history
  • Loading branch information
maximkrouk committed Nov 30, 2022
1 parent 5731d20 commit 9b44b5a
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 20 deletions.
34 changes: 26 additions & 8 deletions Sources/FunctionalConfigurator/Configurator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,18 @@ extension Configurator {
}

public func callAsFunction(_ value: Value) -> Configurator {
_block.configurator.appendingConfiguration { _block.keyPath.embed(value, in: $0) }
_block.configurator.appendingConfiguration {
_block.keyPath.embed(value, in: $0)
}
}

public func set(_ transform: @escaping (inout Value) -> Void) -> Configurator {
_block.configurator.appendingConfiguration { base in
_block.keyPath.embed(
modification(of: _block.keyPath.extract(from: base), with: transform),
modification(
of: _block.keyPath.extract(from: base),
with: transform
),
in: base
)
}
Expand All @@ -157,7 +162,10 @@ extension Configurator {
) -> Configurator {
_block.configurator.appendingConfiguration { base in
_block.keyPath.embed(
_modification(of: _block.keyPath.extract(from: base), with: configuration),
_modification(
of: _block.keyPath.extract(from: base),
with: configuration
),
in: base
)
}
Expand All @@ -167,7 +175,9 @@ extension Configurator {
_ configuration: @escaping (Configurator<Wrapped>) -> Configurator<Wrapped>
) -> Configurator where Value == Wrapped? {
_block.configurator.appendingConfiguration { base in
guard let value = _block.keyPath.extract(from: base) else { return base }
guard let value = _block.keyPath.extract(from: base)
else { return base }

return _block.keyPath.embed(
_modification(of: value, with: configuration),
in: base
Expand All @@ -180,7 +190,8 @@ extension Configurator {
) -> CallableBlock<LocalValue> {
CallableBlock<LocalValue>(
configurator: _block.configurator,
keyPath: _block.keyPath.appending(path: FunctionalKeyPath(keyPath))
keyPath: _block.keyPath
.appending(path: FunctionalKeyPath(keyPath))
)
}

Expand All @@ -195,7 +206,9 @@ extension Configurator {
) -> CallableBlock<LocalValue?> where Value == Wrapped? {
CallableBlock<LocalValue?>(
configurator: _block.configurator,
keyPath: _block.keyPath.appending(path: FunctionalKeyPath(keyPath).optional())
keyPath: _block.keyPath.appending(
path: FunctionalKeyPath(keyPath).optional()
)
)
}

Expand All @@ -216,7 +229,10 @@ extension Configurator {
) -> Configurator where Value: AnyObject {
configurator.appendingConfiguration { base in
keyPath.embed(
_modification(of: keyPath.extract(from: base), with: configuration),
_modification(
of: keyPath.extract(from: base),
with: configuration
),
in: base
)
}
Expand All @@ -226,7 +242,9 @@ extension Configurator {
_ configuration: @escaping (Configurator<Wrapped>) -> Configurator<Wrapped>
) -> Configurator where Wrapped: AnyObject, Value == Wrapped? {
configurator.appendingConfiguration { base in
guard let value = keyPath.extract(from: base) else { return base }
guard let value = keyPath.extract(from: base)
else { return base }

return keyPath.embed(
_modification(of: value, with: configuration),
in: base
Expand Down
5 changes: 4 additions & 1 deletion Sources/FunctionalKeyPath/FunctionalKeyPath.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ public struct FunctionalKeyPath<Root, Value> {
/// - Parameters:
/// - embed: A function that always succeeds in embedding a value in a root.
/// - extract: A function that can optionally fail in extracting a value from a root.
public init(embed: @escaping (Value, Root) -> Root, extract: @escaping (Root) -> Value) {
public init(
embed: @escaping (Value, Root) -> Root,
extract: @escaping (Root) -> Value
) {
self._embed = embed
self._extract = extract
}
Expand Down
21 changes: 10 additions & 11 deletions Tests/DeclarativeConfigurationTests/BuilderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,16 @@ final class BuilderTests: XCTestCase {

let initial = Container()
let actual = Container().builder
.content.scope {
$0
.a(1)
.b(2)
.c(3)
.innerClass
.ifLetScope {
$0
.value(1)
}
}.build()
.content.scope { $0
.a(1)
.b(2)
.c(3)
.innerClass
.ifLetScope { $0
.value(1)
}
}
.build()

XCTAssertNotEqual(actual.content.a, initial.content.a)
XCTAssertNotEqual(actual.content.b, initial.content.b)
Expand Down

0 comments on commit 9b44b5a

Please sign in to comment.