Skip to content

Commit b495022

Browse files
authored
Update proposal with specific code samples
1 parent 783595a commit b495022

File tree

1 file changed

+24
-7
lines changed

1 file changed

+24
-7
lines changed

Documentation/Proposals/NNNN-evaluate-condition.md

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,26 @@ result of the evaluation. The existing `prepare(for:)` method is updated to call
2626

2727
## Detailed design
2828

29-
The signature is `evaluate() async throws -> Evaluation`, where `Evaluation` is
30-
a `typealias` for the tuple already used for the callback in `Kind.conditional`,
31-
containing a boolean result and an optional comment.
29+
The `evaluate()` method is as follows, containing essentially the same logic
30+
as was in `prepare(for:)`:
31+
32+
```swift
33+
public func evaluate() async throws -> EvaluationResult {
34+
switch kind {
35+
case let .conditional(condition):
36+
try await condition()
37+
case let .unconditional(unconditionalValue):
38+
(unconditionalValue, nil)
39+
}
40+
}
41+
```
42+
43+
`EvaluationResult` is a `typealias` for the tuple already used as the result
44+
of the callback in `Kind.conditional`:
45+
46+
```swift
47+
public typealias EvaluationResult = (wasMet: Bool, comment: Comment?)
48+
```
3249

3350
## Source compatibility
3451

@@ -51,7 +68,7 @@ Exposing `ConditionTrait.Kind` and `.kind` was also considered, but it seemed
5168
unnecessary to go that far, and it would encourage duplicating the logic that
5269
already exists in `prepare(for:)`.
5370

54-
In the first draft implementation, the `Evaluation` type was an enum that only
55-
contained the comment in the failure case. It was changed to match the existing
56-
tuple to allow for potentially including comments for the success case without
57-
requiring a change to the API.
71+
In the first draft implementation, the `EvaluationResult` type was an enum that
72+
only contained the comment in the failure case. It was changed to match the
73+
existing tuple to allow for potentially including comments for the success case
74+
without requiring a change to the API.

0 commit comments

Comments
 (0)