1.0.2 • Published 4 years ago

fp-modules v1.0.2

Weekly downloads
18
License
MIT
Repository
github
Last release
4 years ago

fp-modules

fp-modules is a series of functional programming modules. It consists of two parts: core and operators.

Install

$ yarn add fp-modules

# or

$ npm install fp-modules

Usage

We recommend using typescript to follow the proper usage.

operators

operators has a variety of immutable functions. And you can pipe all operators with pipe function.

import { pipe, sort, filter } from 'fp-modules/operators';

const employeeList = getAllEmployees();

// get alphabetically ordered senior employee list.
const seniorEmployeeList = pipe(
  employeeList,
  filter((emp) => emp.position.includes('senior')),
  sort((a, b) => a.name - b.name),
);

core

core is a value wrapper. You can use it by wrapping the values by this module.

For example, You can use Maybe like below.

import { Maybe } from 'fp-modules/core';

const user = getUser('kwoncharles');
const mUser = Maybe.of(user);
const username = mUser
  .map(user => user.name)
  .getOrElse('unnamed');

// If user doens't have name property, 'unnamed' will be logged
console.log('username: ', username);

But you can create your owncore by extending Monad or Functor.

License

fp-modules is MIT licensed.

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0-hotfix1

4 years ago

1.0.0

4 years ago