Skip to content
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

Made Opt a Variant #1313

Merged
merged 6 commits into from
Oct 2, 2023
Merged

Made Opt a Variant #1313

merged 6 commits into from
Oct 2, 2023

Conversation

dansteren
Copy link
Contributor

@dansteren dansteren commented Sep 29, 2023

Opts are now either {Some: value} or {None: null}. You can make None values with the helper None const from Azle. Additionally, Some is a helper function for wrapping your values. Call like this: Some(value).

For example:

import { Canister, None, Opt, query, Some, text } from 'azle';

export default Canister({
    returnSomeText: query([], Opt(text), () => {
        return Some('value');
        // equivalent to: return { Some: 'value' };
    }),
    returnNone: query([], Opt(text), () => {
        return None;
        // equivalent to: return { None: null };
    })
});

@dansteren dansteren force-pushed the opt_variant branch 3 times, most recently from bc003e1 to d810478 Compare October 1, 2023 17:05
@dansteren dansteren force-pushed the opt_variant branch 2 times, most recently from 6c1eba5 to 8b2d279 Compare October 1, 2023 19:52
@dansteren dansteren marked this pull request as ready for review October 1, 2023 20:05
@dansteren dansteren requested a review from lastmjs October 1, 2023 20:15
@lastmjs lastmjs merged commit 9474079 into js_rearchitecture Oct 2, 2023
67 checks passed
@dansteren dansteren deleted the opt_variant branch October 4, 2023 16:38
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