fat-arrow-ts
TypeScript icon, indicating that this package has built-in type declarations

0.14.0 • Public • Published

=> Fat Arrow · GitHub license npm version Tests

Fat Arrow is a library for Typed Functional Programming in TypeScript compatible with Node.js and all major browsers.

⚠️ Alpha release! API may change ⚠️

Installation

npm install fat-arrow-ts   

Setup Jest matchers

Be sure to have a reference to a setup file in your jest.config.ts

// In jest.config.ts

export default {
	setupFilesAfterEnv: [
	  './setupTests.ts'
	],
}

Include this in your setup file

// In setupTests.ts

import 'fat-arrow-ts/src/jest-matchers'

Quick start

import { left, right, Either } from 'fat-arrow-ts';  
  
const getDivision = (numerator: number, denominator: number): Either<Error, number> => {  
    if (denominator === 0) {  
        return left(new Error('Division by zero!'))  
    }  
  
    return right(numerator / denominator)
}
  
const addTwo = (number: number) => number + 2  
  
const print = (value: Either<Error, number>) =>  
    value.fold(  
        (error) => console.error('Doh!', error.message),  
        (result) => console.log(`Result is ${result}. Hooray!`)  
    )  
  
print(getDivision(10, 0).flatMap(addTwo)) // Doh! Division by zero!  
print(getDivision(10, 5).flatMap(addTwo)) // Result is 4. Hooray!  

Docs

SOON...

Package Sidebar

Install

npm i fat-arrow-ts

Weekly Downloads

0

Version

0.14.0

License

MIT

Unpacked Size

58.3 kB

Total Files

50

Last publish

Collaborators

  • m84