-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for delegation and return values with @yieldfrom (#57)
--------- Signed-off-by: Stefan Krastanov <stefan@krastanov.org> Co-authored-by: Stefan Krastanov <stefan@krastanov.org> Co-authored-by: Stefan Krastanov <github.acc@krastanov.org>
- Loading branch information
1 parent
16389d7
commit 727ba4a
Showing
10 changed files
with
164 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,6 @@ jobs: | |
fail-fast: false | ||
matrix: | ||
version: | ||
- '1.2' | ||
- '1.6' | ||
- '1' | ||
os: | ||
|
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
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
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
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
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,55 @@ | ||
using Test | ||
using ResumableFunctions | ||
|
||
@resumable function test_yieldfrom_inner(n) | ||
for i in 1:n | ||
@yield i^2 | ||
end | ||
42, n | ||
end | ||
|
||
@resumable function test_yieldfrom(n) | ||
@yieldfrom [42, 314] | ||
m, n = @yieldfrom test_yieldfrom_inner(n) | ||
@test m == 42 | ||
@yield n | ||
@yieldfrom test_yieldfrom_inner(n+1) | ||
end | ||
|
||
@testset "test_yieldfrom" begin | ||
@test collect(test_yieldfrom(4)) == [42, 314, 1, 4, 9, 16, 4, 1, 4, 9, 16, 25] | ||
end | ||
|
||
@resumable function test_echo() | ||
x = 0 | ||
while true | ||
x = @yield x | ||
end | ||
return "Done" | ||
end | ||
|
||
@resumable function test_forward() | ||
ret = @yieldfrom test_echo() | ||
@test ret == "Done" | ||
@yieldfrom test_echo() | ||
end | ||
|
||
@testset "test_yieldfrom_twoway" begin | ||
forward = test_forward() | ||
@test forward() == 0 | ||
for i in 1:5 | ||
@test forward(i) == i | ||
end | ||
end | ||
|
||
@testset "test_yieldfrom_nonresumable" begin | ||
@test_throws LoadError eval(:(@yieldfrom [1,2,3])) | ||
end | ||
|
||
|
||
@testset "test_yieldfrom_noargs" begin | ||
test_f = :(@resumable function test_yieldfrom_noargs() | ||
@yieldfrom | ||
end) | ||
@test_throws LoadError eval(test_f) | ||
end |
727ba4a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JuliaRegistrator register
Release Notes:
@yieldfrom
to delegate to another resumable function or iterator (similar to Python'syield from
)r = @yieldfrom f
also stores the return value off
inr
727ba4a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Error while trying to register: Changing package repo URL not allowed, please submit a pull request with the URL change to the target registry and retry.
727ba4a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
waiting on JuliaRegistries/General#84867
727ba4a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JuliaRegistrator register
Release Notes:
@yieldfrom
to delegate to another resumable function or iterator (similar to Python'syield from
)r = @yieldfrom f
also stores the return value off
inr
727ba4a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Registration pull request created: JuliaRegistries/General/85267
After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.
This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via: