GitXplorerGitXplorer
a

dgelong

public
13 stars
1 forks
0 issues

Commits

List of commits on branch master.
Unverified
457ad1eae9da091d59a61b98eff3e06437f574f8

get rid of legacy

aalexeyraspopov committed 8 years ago
Unverified
2d392feac325cd8583bceb8650a2b5e46d4578e7

create initial set of exports for Either

aalexeyraspopov committed 8 years ago
Unverified
20e7bd86b7ef7d7bcd221b380d2ee7687615b96d

implement Option.match method

aalexeyraspopov committed 8 years ago
Unverified
19bc835079c8440f18fa2fd3647d67b75ef75fb2

update .npmignore

aalexeyraspopov committed 8 years ago
Unverified
dcd2c0cf4111d94781e088d1f909be21dd5a3fde

get rid of old lib

aalexeyraspopov committed 8 years ago
Unverified
183b617c9a0291e87514d1cb084a1d2a7faac427

get rid of old tests

aalexeyraspopov committed 8 years ago

README

The README file for this repository.

Dgelong

Set of useful first-class structures which allow you to get rid of your developer's pain.

  • Flatten by default.
  • Minimal API sufrace area.
  • Immutable.
  • Lazy evaluation.
  • Full interoperability between all structures and JavaScript natives.

Install

npm install dgelong

Motivation

I don't want make another implementation that requires Ph.D in Math. The usage of monads should be as simple as functional composition f(g(a)). API should be close to native. So if we're talking about data structures, they should be produced in the same way as natives: by calling constructor function with or without new operator (I prefer the second approach).

Usage

import Dgelong from 'dgelong';

Or just use something specific, for example:

import { Option, Either } from 'dgelong';

Option

import { Just, Nothing } from 'dgelong';

function square(n) {
    return n * n;
}

function isEven(n) {
    return n % 2 ? Nothing() : Just(n);
}

new Just(5)
    .map(square) // returns Just(25)
    .map(isEven) // returns Nothing()
    .map(alert); // won't be executed

Either

import { Success, Failure } from 'dgelong/either';

function validateUserPassword(password) {
  if (password.length < 10) return Failure('Password is too short');
  if (!/[0-9]/g.test(password)) return Failure('Password should contain numbers');

  return Success(password);
}

validateUserPassword('boo')
  .map(savePassword, showError);