Skip to content

Releases: VitorLuizC/maybe

Version 2.0.0

08 Mar 19:13
Compare
Choose a tag to compare

Breaking Changes

  • Maybe factory function was renamed to createMaybe.

  • None and isNone were respectively renamed to Nothing and isNothing.

  • Method then was removed from Maybe.

    Use method map instead, which has similar behavior.

    This partially fixes #2.

  • The functions isMaybe and isNothing (old isNone) was uncoupled from Maybe.

    They can be named imported.

    import { isMaybe, isNothing } from '@vitorluizc/maybe';
  • All documentation is generated from TSDocs by Typedoc and can be founded on https://github.com/VitorLuizC/maybe/tree/master/docs.

New features

Some<T> and None<T> functions

They also creates Maybe<T> instances, but they diverge about value wrapped in it.

  • None<T>: creates an instance of Maybe<T> from no value (or Nothing).

  • Some<T>: receives a value of type T and uses it to create the instance of Maybe<T>, it will throw an error if the value is Nothing.

const integer = (value: number) => (
  Number. isSafeInteger(value)
    ? Some<number>(value)
    : None<number>()
);

integer(NaN);
//=> Maybe<number>

This fixes #1.

Tree-shake as default

The functions get, map and match were uncoupled from Maybe and can be used with any value of type T | Nothing.

import { match, Nothing } from '@vitorluizc/maybe';

match(names as string[] | Nothing, {
  none: () => '',
  some: (names) => names.join(' '),
});

This fixes #3.

match function and Maybe's match method

They are pattern matching function that receives an object with properties some and none to handle the value and return something.

match(names as string[] | Nothing, {
  none: () => '',
  some: (names) => names.join(' '),
});

This fixes #4.

Maybe's unwrap method

Return Maybe wrapped value (unwraps it).

createMaybe<string>().unwrap();
//=> undefined

createMaybe<string>('Max').unwrap();
//=> 'Max'

All Changes

v1.0.0...v2.0.0

Version 1.0.0

13 Feb 22:16
Compare
Choose a tag to compare
v1.0.0

:bookmark: bump to version 1.0.0