Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

algebraic-types

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

algebraic-types

Algebraic Types is a small library with largely the same surface area as [daggy](https://github.com/fantasyland/daggy), with a couple of small differences.

  • 0.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3
Maintainers
1
Weekly downloads
 
Created
Source

Algebraic Types

Algebraic Types is a small library with largely the same surface area as daggy, with a couple of small differences.

  1. Daggy's cata is known as match, and will explicitly fail if exhaustive type matching is not performed.
  2. Constructor variables are themselves tagged using either variable, recursive or typedVariable functions. This allows constructors to fail on invalid inputs.

Example

const {
  createUnionType,
  recursive,
  variable
} = require('algebraic-types');

const BinaryTree = createUnionType('BinaryTree', {
  Leaf: [variable('a')],
  Branch: [recursive('left'), recursive('right')]
});

const myTree = BinaryTree.Branch(
  BinaryTree.Leaf(42),
  BinaryTree.Leaf(43)
);

myTree.match({
  Leaf: x => x * x
});
// Error: Non exhaustive pattern matching. Branch missing

FAQs

Package last updated on 09 Jan 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc