Releases: VitorLuizC/maybe
Version 2.0.0
Breaking Changes
-
Maybefactory function was renamed tocreateMaybe. -
NoneandisNonewere respectively renamed toNothingandisNothing. -
Method
thenwas removed fromMaybe.Use method
mapinstead, which has similar behavior.This partially fixes #2.
-
The functions
isMaybeandisNothing(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 typeTand 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'All Changes
Version 1.0.0
v1.0.0 :bookmark: bump to version 1.0.0