Skip to content

Replace Nullable with Option in assemblyscript - #944

Merged
dOrgJelli merged 1 commit into
prealpha-devfrom
809-option-type
Jun 23, 2022
Merged

Replace Nullable with Option in assemblyscript#944
dOrgJelli merged 1 commit into
prealpha-devfrom
809-option-type

Conversation

@fetsorn

@fetsorn fetsorn commented Jun 22, 2022

Copy link
Copy Markdown
Contributor

Replaces custom Nullable type with Option type from as-container. Resolves #809.

Recap:
We want to represent values which could be "null". Assemblyscript has nullable reference types, e.g. "string | null", but does not support nullable basic types, e.g. "u32", so we wrap primitives in a custom Nullable type, like "Nullable".

This PR wraps basic types in an Option container, like "Option.Some(10)" and "Option.None()". The Option container comes from has a robust implementation and a rust-inspired interface, similar to the Result type we are already using.

This PR does not wrap reference types in Option, they are still implemented as " | null" because " | null" allows for optional fields in the the input arguments to the bindings. Option does not allow optional fields, all missing arguments have to be written as Option.None<>().

  • Replace Nullable with Option

@fetsorn fetsorn changed the title 809 option type Replace Nullable with Option in assemblyscript Jun 22, 2022
@cbrzn
cbrzn changed the base branch from prealpha to prealpha-dev June 22, 2022 10:39
@fetsorn fetsorn closed this Jun 22, 2022
@fetsorn fetsorn reopened this Jun 23, 2022
@fetsorn
fetsorn marked this pull request as ready for review June 23, 2022 16:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants