# @execonline-inc/maybe-adapter

> Convert types to and from Maybeasy

Latest version **4.7.0** (published 2022-11-09) · ISC license · 0 weekly downloads

## Install

```sh
npm install @execonline-inc/maybe-adapter
pnpm add @execonline-inc/maybe-adapter
yarn add @execonline-inc/maybe-adapter
bun add @execonline-inc/maybe-adapter
```

## Health

**Score 35/100 (D)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 4.7.0 |
| Published | 2022-11-09 |
| First published | 2019-12-20 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 6 |
| Unpacked size | 5.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 5 |
| Author | Ryan L. Bell |
| Maintainers | kofno |

## Links

- npm: https://www.npmjs.com/package/@execonline-inc/maybe-adapter
- Repository: https://github.com/execonline-inc/CooperTS
- Homepage: https://github.com/execonline-inc/CooperTS#readme
- Issues: https://github.com/execonline-inc/CooperTS/issues
- npm.io page: https://npm.io/package/@execonline-inc/maybe-adapter

## Dependencies (6)

- [ajaxian](https://npm.io/package/ajaxian.md) ^4.4.0
- [jsonous](https://npm.io/package/jsonous.md) ^7.3.0
- [resulty](https://npm.io/package/resulty.md) ^5.0.0
- [maybeasy](https://npm.io/package/maybeasy.md) ^5.0.0
- [taskarian](https://npm.io/package/taskarian.md) ^5.3.0
- [@kofno/piper](https://npm.io/package/@kofno/piper.md) ^4.3.0

## Recent versions

- 4.7.0 (latest) — 2022-11-09
- 4.6.0 — 2022-11-09
- 4.5.0 — 2022-10-27
- 4.4.1 — 2022-09-06
- 4.4.0 — 2022-08-23
- 4.3.0 — 2022-03-25
- 4.2.0 — 2021-07-01
- 4.1.0 — 2021-06-15
- 4.0.0 — 2021-05-13
- 3.0.0 — 2020-12-09
- 2.0.0 — 2020-12-07
- 1.2.0 — 2020-08-13
- 1.1.0 — 2020-08-13
- 1.0.2 — 2020-02-03
- 1.0.1 — 2019-12-20

## README

# `maybe-adapter`

The `maybe-adapter` package provides functions to convert to/from `Maybe` types.

## Functions

### `toResult`

This function has a curried and non-curried form. It takes an error and a `Maybe`. When the `Maybe` is a `Just`, a successful `Result` is returned with the wrapped value, otherwise an error `Result` is returned with the given error value.

```ts
import { toResult } from '@execonline-inc/maybe-adapter';
import { nothing } from 'maybeasy';

toResult<string, number>('an error message')(nothing());
```

### `toTask`

This function has a curried and non-curried form. It takes an error and a `Maybe`. When the `Maybe` is a `Just`, a succeeding `Task` is returned with the wrapped value, otherwise a failing `Task` is returned with the given error value.

```ts
import { toTask } from '@execonline-inc/maybe-adapter';
import { nothing } from 'maybeasy';

toTask<string, number>('an error message')(nothing());
```

### `fromBool`, `when`

This function has a curried and non-curried form. It wraps a given value in a `Maybe` depending on either the given boolean value or boolean return value of the given function.

Also, if the first argument is a function, the second argument is passed to that function for evaluation. (See advanced usage example)

Aliased as `when`

```ts
import { fromBool } from '@execonline-inc/maybe-adapter';

fromBool(true)(123);
fromBool((): boolean => true)(123);
// Just<123>

// Advanced usage.
mapMaybe(when(even), [1, 2, 3, 4]);
// [2, 4]
```

---
_Source: https://npm.io/package/@execonline-inc/maybe-adapter · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
