Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Return the first step from
ConjunctionBuilder
The result builder and its tests are only supported in swift 5.4+.
- Loading branch information
1 parent
54c44fa
commit 415816c
Showing
3 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// | ||
// ConjunctionBuilder.swift | ||
// LightweightValidation | ||
// | ||
// Created by user on 19.06.2021. | ||
// Copyright © 2021 yes. All rights reserved. | ||
// | ||
|
||
#if swift(>=5.4) | ||
import Foundation | ||
|
||
@resultBuilder | ||
public struct ConjunctionBuilder { | ||
public static func buildBlock <T, E> (_ validations: V<T, E>...) -> V<T, E> { | ||
validations[0] | ||
} | ||
} | ||
|
||
public extension V { | ||
static func all(@ConjunctionBuilder _ validations: () -> V<T, E>) -> V<T, E> { | ||
validations() | ||
} | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// | ||
// ConjunctionBuilderTests.swift | ||
// LightweightValidationTests | ||
// | ||
// Created by user on 19.06.2021. | ||
// Copyright © 2021 yes. All rights reserved. | ||
// | ||
|
||
#if swift(>=5.4) | ||
import LightweightValidation | ||
import XCTest | ||
|
||
class ConjunctionBuilderTests: XCTestCase { | ||
func testValidStepShouldReturnItself() { | ||
let sut = Response.SimpleValidationResult.all { | ||
true <?> StringError("never happens") | ||
} | ||
XCTAssertTrue(sut.isValue) | ||
} | ||
} | ||
#endif |