# functional-dag

> a Functional Directed Acyclic Graph

Latest version **2.0.2** (published 2016-10-11) · MPL-2.0 license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install functional-dag
pnpm add functional-dag
yarn add functional-dag
bun add functional-dag
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 2.0.2 |
| Published | 2016-10-11 |
| First published | 2016-02-12 |
| Weekly downloads | 0 |
| License | MPL-2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | mjbecze |
| Maintainers | null_radix |
| Keywords | directed graph, dag, DAG, acyclic, acyclic graph, functional, graph |

## Links

- npm: https://www.npmjs.com/package/functional-dag
- Repository: https://github.com/wanderer/functional-dag
- Issues: https://github.com/wanderer/functional-dag/issues
- npm.io page: https://npm.io/package/functional-dag

## Dependencies (1)

- [generic-digraph](https://npm.io/package/generic-digraph.md) ^3.0.0

## Alternatives

- [apollo-link-http-common](https://npm.io/package/apollo-link-http-common.md) — 879.0K weekly downloads
- [react-relay](https://npm.io/package/react-relay.md) — 336.8K weekly downloads
- [relay-test-utils](https://npm.io/package/relay-test-utils.md) — 181.6K weekly downloads
- [@vendure/core](https://npm.io/package/@vendure/core.md) — 14.8K weekly downloads
- [@pnpm/deps.graph-sequencer](https://npm.io/package/@pnpm/deps.graph-sequencer.md) — 13.4K weekly downloads

## Recent versions

- 2.0.2 (latest) — 2016-10-11
- 2.0.1 — 2016-04-13
- 2.0.0 — 2016-04-13
- 1.1.0 — 2016-02-21
- 1.0.0 — 2016-02-18
- 0.0.0 — 2016-02-12

## README

# DEPRICATED - GO HERE https://github.com/wanderer/functional-trie  
[![NPM Package](https://img.shields.io/npm/v/functional-dag.svg?style=flat-square)](https://www.npmjs.org/package/functional-dag)
[![Build Status](https://img.shields.io/travis/wanderer/functional-dag.svg?branch=master&style=flat-square)](https://travis-ci.org/wanderer/functional-dag)
[![Coverage Status](https://img.shields.io/coveralls/wanderer/functional-dag.svg?style=flat-square)](https://coveralls.io/r/wanderer/functional-dag)

[![js-standard-style](https://cdn.rawgit.com/feross/standard/master/badge.svg)](https://github.com/feross/standard)  

This is a Functional Directed Acyclic Graph implementation. [generic-digraph](https://github.com/wanderer/generic-digraph) is the imperative version. 

# USAGE

```javascript
const Vertex = require('functional-dag')

// to start with the graph is just a single vertex
var vertex = new Vertex()

// now lets add an edge to the vertex named "bob" that points to another vertex with the value "alice"
vertex = vertex.set('friend', 'alice')

// if paths have more than one name in them they can arrays
vertex = vertex.set(['friend', 'brother'], 'bob')
// now the graph looks like:
// [vertex]---friend--->[alice]---brother-->[bob]

// path names and vertex values can be anything
vertex = vertex.set([new Buffer('friend'), 5, true, {}, new Date()], Array())

// edges are stored in a Map
vertex.edges // Map{}

//you can iterate the graph to get all of its vertices
var vertices = [...vertex]

// you can also iterate a path
vertices = [...vertex.iterPath(['friend', 'brother'])]

// delete an edge
vertex = vertex.delete('friend')
// now the vertex is empty
vertex.isEmpty()
```

# API
This has about same API as [generic-digraph](https://github.com/wanderer/generic-digraph/blob/master/docs/index.md). With the execption that any operation that changes state returns a new copy with the changes instead of applying them directly. This affects all Set and Delete functions.

## batch (operations)   

The batch functions should be more effeciant then single operations for functional DAGs     
**params**   

- operations {array} - an array of operation to apply to the graph. Each entry should be in the form of [op, path, argument]. Where `op` can be `set`, `del` or `setValue`.   

**example**
```javascript
var graph = new Vertex()
const pathA = ['a', 'b']
const pathB = ['a^', 'b^']
const commonVertex = new Vertex('common')
const batch = [
  ['set', pathA, commonVertex],
  ['set', pathB, commonVertex]
]

graph = graph.batch(batch)
// the graph should now be
//  ,->o.
// o     o
//  `->o'
```

# LICENSE
[MPL-2.0](https://tldrlegal.com/license/mozilla-public-license-2.0-(mpl-2))

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