# as-container

> assemblyscript version of Rust Option and Result and Box etc.

Latest version **0.8.0** (published 2023-07-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install as-container
pnpm add as-container
yarn add as-container
bun add as-container
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.8.0 |
| Published | 2023-07-03 |
| First published | 2021-03-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 68 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 26 |
| Author | yjhmelody |
| Maintainers | yjhmelody |
| Keywords | assemblyscript, util, container, option, result, box |

## Links

- npm: https://www.npmjs.com/package/as-container
- Repository: https://github.com/yjhmelody/as-container
- Homepage: https://github.com/yjhmelody/as-container#readme
- Issues: https://github.com/yjhmelody/as-container/issues
- npm.io page: https://npm.io/package/as-container

## Alternatives

- [react-native-root-siblings](https://npm.io/package/react-native-root-siblings.md) — 102.9K weekly downloads
- [@praxisui/dialog](https://npm.io/package/@praxisui/dialog.md) — 2.0K weekly downloads
- [easy-toggle-state](https://npm.io/package/easy-toggle-state.md) — 350 weekly downloads
- [ngx-lightbox-evp](https://npm.io/package/ngx-lightbox-evp.md) — 19 weekly downloads
- [react-native-modal-translucent-axton](https://npm.io/package/react-native-modal-translucent-axton.md) — 4 weekly downloads

## Recent versions

- 0.8.0 (latest) — 2023-07-03
- 0.7.0 — 2023-02-07
- 0.6.1 — 2021-08-20
- 0.6.0 — 2021-07-30
- 0.5.2 — 2021-05-08
- 0.5.1 — 2021-05-07
- 0.4.0 — 2021-04-09
- 0.3.0 — 2021-04-01
- 0.2.0 — 2021-03-31
- 0.1.0 — 2021-03-29

## README

# as-container

![CI](https://github.com/yjhmelody/as-container/workflows/CI/badge.svg)
[![npm version](https://img.shields.io/npm/v/as-container?color=light-green&label=npm%20package)](https://img.shields.io/npm/v/as-container?color=light-green&label=npm%20package)
![GitHub release (latest by date)](https://img.shields.io/github/v/release/yjhmelody/as-container)

as-container provides some utils such as `Option` and `Result` inspired by Rust for other people to use.

## APIs

### Box

Box is used to wrap non-nullable(or primitive) value such as i32. Box offers all operator overloads to call the inner type operator.

Box usage scenarios are mainly used when a function or field needs to be null. This is very common in the case of generic functions and generic classes. The generics you write for reference types cannot be used for basic types, and Box is a reference type.

```ts
import { Box } from "as-container";

let box = Box.from(2);
let box2 = Box.from(1);
expect(box == box2).toStrictEqual(false);
expect(box != box2).toStrictEqual(true);
```

More examples can be found in [unit tests](./assembly/__tests__/box.spec.ts)

### Option

Option offers some operations inspired by Rust.

```ts
import { Option } from "as-container";

const x = Option.Some("some");
expect(x.map<string>((s) => s + s).unwrap()).toBe("somesome");
```

More examples can be found in [unit tests](./assembly/__tests__/primitive/option.spec.ts)

### Result

Result offers some operations inspired by Rust.

```ts
import { Result } from "as-container";

const x = Result.Ok<string, string>("233");
expect(x.map<string>((s) => s + s).unwrap()).toBe("233233");
```

More examples can be found in [unit tests](./assembly/__tests__/primitive/result.spec.ts)

### Others

`as-container` offers two versions of Result/Option. They provide the same API, but different implementations.

The default version can handle any type including primitive type. But because the primitive types need one more byte to record state, it may take more overhead.

If you always use reference types as Option/Result parameters and need better performance, then you can use the type with the same name under `as-container/reference`.

---
_Source: https://npm.io/package/as-container · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
