Skip to content

Commit

Permalink
Deprecate implicit tuple construction in yieldAsync
Browse files Browse the repository at this point in the history
It was a bad idea from the start. Regular `yield` statement in Nim does
not accept multiple values - why should we? A DSL should mimic the
syntax and semantics as close as possible. Being more permissive is
still a deviation from the original, which increases cognitive load.
  • Loading branch information
SirNickolas committed Mar 14, 2024
1 parent 745ed7c commit 6d662bb
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/asyncIters/private/asyncIter.nim
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ type Inaccessible = object
template yieldAsync*(phantom: Inaccessible)
{.error: "congratulations, you've found a way to invoke me".} = discard

macro yieldAsync*(values: varargs[typed]): untyped =
macro yieldAsync*(values: varargs[typed]): untyped
{.deprecated: "enclose multiple values in parentheses to yield them as a tuple".} =
## Transfer control to the caller of the async iterator. If several values are passed, they
## are wrapped in a tuple.
case values.len:
Expand Down
4 changes: 1 addition & 3 deletions tests/test.nim
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,9 @@ proc main =
test "`awaitIter` can unpack simple tuples":
asyncIter:
iterator indexedStrings: Future[(int, string)] =
yieldAsync 1, "test"
yieldAsync (1, "test")

iterator indexedPositions: Future[(int, string, tuple[x, y: float])] =
yieldAsync 1, "here", (2.0, 4.0)
yieldAsync (1, "here", (2.0, 4.0))

var n = 0
Expand All @@ -114,7 +112,7 @@ proc main =
check x == 2.0
check y == 4.0
n += 1
check n == 8
check n == 4

test "`awaitIter` can unpack a 1-element tuple":
asyncIter:
Expand Down

0 comments on commit 6d662bb

Please sign in to comment.