0.14.0 • Published 2 years ago

fat-arrow-ts v0.14.0

Weekly downloads
10
License
MIT
Repository
github
Last release
2 years ago

=> 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.

:warning: Alpha release! API may change :warning:

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...

0.14.0

2 years ago

0.13.1

2 years ago

0.13.2

2 years ago

0.12.0

2 years ago

0.12.1

2 years ago

0.9.0

3 years ago

0.8.0

3 years ago

0.7.1

3 years ago

0.7.0

3 years ago

0.6.1

3 years ago

0.6.0

3 years ago

0.5.2

3 years ago

0.5.0

3 years ago

0.5.1

3 years ago

0.4.0

3 years ago

0.3.0

3 years ago

0.2.11

3 years ago

0.2.10

3 years ago

0.2.9

3 years ago

0.2.8

3 years ago

0.2.7

3 years ago

0.2.6

3 years ago

0.2.5

3 years ago

0.2.4

3 years ago

0.2.3

3 years ago

0.2.2

3 years ago

0.2.1

3 years ago

0.2.0

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago