-
Notifications
You must be signed in to change notification settings - Fork 323
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use only Type instances as keys for State #7585
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -158,23 +158,23 @@ optimize_fragments : Vector SQL_Fragment -> Vector SQL_Fragment | |
optimize_fragments fragments = | ||
builder = Vector.new_builder | ||
go elem = | ||
last_part = State.get SQL_Fragment.Code_Part | ||
last_part = State.get SQL_Fragment | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Restricting keys to types is simpler. |
||
case elem of | ||
SQL_Fragment.Code_Part code -> | ||
new_part = case last_part of | ||
Nothing -> SQL_Fragment.Code_Part code | ||
SQL_Fragment.Code_Part other -> SQL_Fragment.Code_Part other+code | ||
State.put SQL_Fragment.Code_Part new_part | ||
State.put SQL_Fragment new_part | ||
SQL_Fragment.Interpolation _ -> | ||
case last_part of | ||
Nothing -> Nothing | ||
SQL_Fragment.Code_Part _ -> | ||
builder.append last_part | ||
State.put SQL_Fragment.Code_Part Nothing | ||
State.put SQL_Fragment Nothing | ||
builder.append elem | ||
State.run SQL_Fragment.Code_Part Nothing <| | ||
State.run SQL_Fragment Nothing <| | ||
fragments.each go | ||
last_part = State.get SQL_Fragment.Code_Part | ||
last_part = State.get SQL_Fragment | ||
case last_part of | ||
Nothing -> Nothing | ||
SQL_Fragment.Code_Part _ -> builder.append last_part | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from Standard.Base import all | ||
|
||
import Standard.Base.Runtime.State | ||
import Standard.Base.Errors.Common.Unsupported_Argument_Types | ||
|
||
from Standard.Test import Test, Test_Suite | ||
import Standard.Test.Extensions | ||
|
||
spec = Test.group "State" <| | ||
Test.specify "Type as a key" <| | ||
s = State.run Test 42 <| | ||
State.get Test | ||
s . should_equal 42 | ||
|
||
Test.specify "string as a key" <| | ||
s n = State.run "my_state" n <| | ||
State.get "my_state" | ||
|
||
p = Panic.catch Unsupported_Argument_Types (s 42) err-> | ||
err.payload | ||
|
||
Meta.type_of p . should_equal Unsupported_Argument_Types | ||
|
||
|
||
main = Test_Suite.run_main spec |
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.
The signature of
run : Any -> Any -> Any -> Any
remains unchanged, as we don't have any type fortype Some_Type
.