# adt-state

> Function based State ADT

Latest version **1.0.2** (published 2018-11-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install adt-state
pnpm add adt-state
yarn add adt-state
bun add adt-state
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2018-11-04 |
| First published | 2018-05-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 10.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | Francisco Tavares de Lima Neto |
| Maintainers | francisco.tln |
| Keywords | ADT, State |

## Links

- npm: https://www.npmjs.com/package/adt-state
- Repository: https://github.com/franciscotln/adt-state
- Homepage: https://github.com/franciscotln/adt-state#readme
- Issues: https://github.com/franciscotln/adt-state/issues
- npm.io page: https://npm.io/package/adt-state

## Alternatives

- [@reckona/mreact-store](https://npm.io/package/@reckona/mreact-store.md) — 976 weekly downloads
- [regular-state](https://npm.io/package/regular-state.md) — 410 weekly downloads
- [@pacote/flux-actions](https://npm.io/package/@pacote/flux-actions.md) — 65 weekly downloads
- [@pilotlab/lux-debug](https://npm.io/package/@pilotlab/lux-debug.md) — 39 weekly downloads
- [vue-persist-state](https://npm.io/package/vue-persist-state.md) — 19 weekly downloads

## Recent versions

- 1.0.2 (latest) — 2018-11-04
- 1.0.1 — 2018-05-27
- 1.0.0 — 2018-05-27

## README

# adt-state

Function based State algebraic data type for safe code

`npm install adt-state`

## Examples

### Applicative
```js
const pipe = require('adt-state/Helpers/pipe');
const ap = require('adt-state/State/operators/ap');
const runWith = require('adt-state/State/runners/run-with');
const { get, of } = require('adt-state/State/factory/');

// add :: Number -> Number -> Number
const add = x => y => x + y;

// ofAdd :: State s (Number -> Number -> Number)
const ofAdd = of(add);

// getAdd :: State s a
const getAdd = get(add);

const res1 = pipe(
  ap(of(1)),
  ap(of(2)),
  runWith(5)
)(ofAdd);

console.log(res1) // [ Resultant 3, State 5 ]

const res2 = pipe(
  ap(of(1)),
  runWith(5)
)(getAdd);

 console.log(res2); // [ Resultant 6, State 5 ]
```

### Getting State and mapping over the resultant
```js
const pipe = require('adt-state/Helpers/pipe');
const get = require('adt-state/State/factory/get');
const map = require('adt-state/State/operators/map');
const runWith = require('adt-state/State/runners/run-with');

const res = pipe(
  map(x => x * 3),
  runWith(5)
)(get());

console.log(res); // [ Resultant 15, State 5 ]
```

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