as-option
v0.0.2
Published
Zero cost Option type for AssemblyScript
Downloads
711
Maintainers
Readme
Option
Work In Progress
Zero cost abstraction for optional container (Option<T>
). This abstraction is completely free for reference types, while other types that cannot yet be nullable such as bool
, i32
or f64
will be wrapped in the class.
Usage
import { Option, Some, None } from "as-option/assembly"
function maybeArray(arr: i32[] | null): Option<i32[]> {
if (arr != null) {
return Some(arr);
} else {
return None<i32[]>();
}
}
function getDefaultFloat(input: Option<f64>): f64 {
return input.unwrapOr(0.0);
}
function getDefaultInt(input: Option<i32>): i32 {
return input.unwrapOrElse(() => -1);
}
TODO
- [ ] Support zero cost for types with
sizeof<T>()
<= 16 - [ ] Tests