Breaking Changes
-
Maybe
factory function was renamed tocreateMaybe
. -
None
andisNone
were respectively renamed toNothing
andisNothing
. -
Method
then
was removed fromMaybe
.Use method
map
instead, which has similar behavior.This partially fixes #2.
-
The functions
isMaybe
andisNothing
(oldisNone
) was uncoupled fromMaybe
.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 ofMaybe<T>
from no value (orNothing
). -
Some<T>
: receives a value of typeT
and uses it to create the instance ofMaybe<T>
, it will throw an error if the value isNothing
.
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'