New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@unsplash/sum-types

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@unsplash/sum-types

Safe, ergonomic, non-generic sum types in TypeScript.

  • 0.4.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

@unsplash/sum-types

Safe, ergonomic, non-generic sum types in TypeScript.

Documentation: unsplash.github.io/sum-types

import * as Sum from "@unsplash/sum-types"

type Weather = Sum.Member<"Sun"> | Sum.Member<"Rain", number>
const Weather = Sum.create<Weather>()

const getRainfall = Weather.match({
  Rain: n => `${n}mm`,
  Sun: () => "none",
})

const todayWeather = Weather.mk.Rain(5)

getRainfall(todayWeather) // '5mm'

Installation

The library is available on the npm registry: @unsplash/sum-types

Note that due to usage of Proxy and Symbol this library only supports ES2015+.

The following bindings are also available:

Motivation

The library solves a number of problems we've experienced at Unsplash with alternative libraries in this space. Specifically:

  • Convenient member constructor functions are provided, unlike ts-adt.
  • The API is small, simple, and boilerplate-free, unlike tagged-ts.
  • Pattern matching is curried for use in pipeline application and function composition, unlike @practical-fp/union-types.
  • Types are not inlined in compiler output, improving readability and performance at scale, unlike unionize.

The compromise we've made to achieve this is to not support generic sum types.

Keywords

FAQs

Package last updated on 04 Oct 2023

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