# uxadt

> Cross-platform embedded representation for algebraic data types, values, and common operations.

Latest version **0.1.1** (published 2018-01-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install uxadt
pnpm add uxadt
yarn add uxadt
bun add uxadt
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.1 |
| Published | 2018-01-03 |
| First published | 2014-01-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 7 |
| Author | Andrei Lapets |
| Maintainers | lapets |
| Keywords | algebraic, data, types, adt, datatypes, functional, case, match, pattern, unification |

## Links

- npm: https://www.npmjs.com/package/uxadt
- Repository: https://github.com/lapets/uxadt
- Homepage: http://uxadt.org
- Issues: https://github.com/lapets/uxadt/issues
- npm.io page: https://npm.io/package/uxadt

## Dependencies (2)

- [chai](https://npm.io/package/chai.md) ^4.1.2
- [mocha](https://npm.io/package/mocha.md) ^4.0.1

## Alternatives

- [@mce/gif](https://npm.io/package/@mce/gif.md) — 2.6K weekly downloads
- [cleanse](https://npm.io/package/cleanse.md) — 173 weekly downloads
- [str](https://npm.io/package/str.md) — 127 weekly downloads
- [naming](https://npm.io/package/naming.md) — 95 weekly downloads
- [tap-telco-api](https://npm.io/package/tap-telco-api.md) — 19 weekly downloads

## Recent versions

- 0.1.1 (latest) — 2018-01-03
- 0.1.0 — 2018-01-02
- 0.0.16 — 2014-07-08
- 0.0.14 — 2014-07-08
- 0.0.13 — 2014-07-08
- 0.0.12 — 2014-07-08
- 0.0.11 — 2014-07-08
- 0.0.10 — 2014-06-29
- 0.0.8 — 2014-06-29
- 0.0.6 — 2014-06-05
- 0.0.5 — 2014-06-03
- 0.0.4 — 2014-06-03
- 0.0.3 — 2014-06-03
- 0.0.2 — 2014-01-13

## README

# uxadt

Cross-platform embedded representation for algebraic data types, values, and common operations.

[![npm version and link.](https://badge.fury.io/js/uxadt.svg)](https://badge.fury.io/js/uxadt)

This family of libraries supports a cross-platform embedded representation for algebraic data type (ADT) values, and platform-specific embedded programming abstractions for common operations (such as pattern matching) on algebraic data type values.

## Package Installation and Usage

It is possible to use the library within a [Node.js](http://www.nodejs.org) module in the following way:
```javascript
var uxadt = require("./uxadt.js");
```
It is possible to use the library within an HTML page in the following way:
```html
<script src="uxadt.js"></script>
```
You may want to define `_` for the sake of concision:
```javascript
var _ = null;
```
It does not matter what is assigned to `_`, as long as it is *not a uxadt value*.

## Examples

The following is a simple algebraic data type definition:
```javascript
uxadt._({
    Node: [_, _],
    Leaf: []
  });
```
To better document the implicit constraints associated with the definition, it is possible to provide an explicit name for the algebraic data type and the types of the constructor arguments (no static or dynamic checking of the constraints implied by this information is currently supported by the library itself):
```javascript
uxadt._('Tree', {
    Node: ['Tree', 'Tree'],
    Leaf: []
  });
```
An individual value can then be built up as an expression in the following way:
```javascript
Node(Node(Leaf(), Leaf()), Leaf())
```
Below is a simple recursive function that counts the number of nodes in a tree value (i.e., a value that corresponds to the algebraic data type definition in the above example):
```javascript
function size(t) {
  return t
    ._(Leaf(),     function()    { return 1; })
    ._(Node(_, _), function(x, y){ return 1 + size(x) + size(y); })
    .end;
}
```
The library provides an alternate interface for using pattern matching that follows a more imperative paradigm:
```javascript
function size(t) {
  if (t._(Leaf())) {
    return 1;
  } else if (t._(Node(_, _))) {
    [x, y] = t.matched();
    return 1 + size(x) + size(y);
  }
}
```

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