https://github.com/hyper63/either
https://github.com/hyper63/either
Last synced: about 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/hyper63/either
- Owner: hyper63
- Created: 2021-01-16T20:34:27.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2021-06-18T19:07:42.000Z (almost 5 years ago)
- Last Synced: 2025-01-13T05:41:42.741Z (about 1 year ago)
- Language: TypeScript
- Size: 24.4 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
either
Either is a ADT that can return one of two types a left or right. Useful for error handling, specifically handling nulls and exceptions in your pure application workflow.
---
## Table of Contents
- [Getting Started](#getting-started)
- [Installation](#installation)
- [Features](#features)
- [Methods](#methods)
- [Contributing](#contributing)
- [License](#license)
## Getting Started
```js
import { Either } from "https://x.nest.land/either/@1.0.6/mod.ts";
const { fromNullable } = Either;
fromNullable(null)
.fold(
(e) => console.log("Is Null"),
(r) => console.log(r),
);
```
## Installation
This is a Deno module available to import from https://nest.land/package/either
deps.js
```
export { Either } from 'https://x.nest.land/either@1.0.6/mod.ts'
```
## Features
- fromNullable - `fromNullable(x).fold(console.error, console.log)`
- tryCatch - `tryCatch(doFn).fold(console.error, console.log)`
## Methods
- of - Returns an Either as a Right
- fromNullable - takes a value and if the value is null returns a Left and if
the value is not null returns a Right
- tryCatch - takes a function that is invoked and if an exception is thrown it
returns a Left with the Error as the value, otherwise it returns a Right.
## Contributing
Pull Requests are welcome
## License
MIT
## Acknowledgements
The core code for this library was initiated from code shared by Brian Londorf
in a course from frontend masters. If you want to learn more about functional
programming in javascript check it out:
https://frontendmasters.com/courses/hardcore-js-v2/