You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The top-level namespace-style export has been removed. If you were relying on the static members to be present when doing import Maybe from 'true-myth/maybe' or import Result from 'true-myth/result';, you can replace them with import * as Maybe from 'true-myth/maybe'; or import * as Result from 'true-myth/result';. This should make for much better tree-shaking with bundlers like Rollup, which can see “through” a namespace import in a way they cannot with a manually-created namespace object. Where you want to maintain the type and namespace imports, you can do this:
import*asMaybefrom'true-myth/maybe';typeMaybe<T>=Maybe.Maybe<T>;// convenience alias
In general, though, you should prefer to simply import the named functions instead:
There are no longer separate classes for Just, Nothing, Ok, and Err. This substantially reduces the size of the library, and should hopefully improve browsers' ability to optimize code using these, since there is now only one class in each case: Maybe and Result. The public API for the classes is unchanged, but if you relied on instanceof checks against those classes anywhere, those checks will no longer work.
The exported Variant types are now frozen, constant objects, not TypeScript enums. This should not break anyone, since the only difference in observable behavior between an enum and a const is the ability to do a “reverse lookup” on an enum—but since the field names and their values are identical, this just means shipping less, and faster, code.
The isJust, isNothing, isOk, and isErr methods have been converted to getters. This makes them muchmore immediately useful in contexts where invoking a function is annoying, for any reason—for example, in Ember templates.
We no longer publish CommonJS modules, only ES Modules.
Dropped support for Node versions earlier than Node 12 LTS.
Support for versions of TypeScript before 4.0 have been removed, to enable the type-safe re-implementation of Maybe.all.
The MaybeShape and ResultShape interfaces are no longer exported. These were never intended for public reimplementation, and there is accordingly no value in their continuing to be public.
A number of aliases (originally designed to make migration from e.g. Folktale easier) have been removed:
cata: use match
chain and flatMap: use andThen
maybeify and transmogrify: use wrapReturn
unsafelyGet, unsafeGet, and unsafelyUnwrap: use .isJust/.isOk then .value
unsafelyGetErr and unsafelyUnwrapErr: use .isErr then .error
getOr: use unwrapOr
getOrElse: use unwrapOrElse
fromNullable and maybe:
import Maybe and use its static constructor Maybe.of
import the module as namespace and use Maybe.of
import of and alias it as you like
⭐ Added
We introduced a new Maybe.transposeArray, which is a type-safe, renamed, merged version of Maybe.tuple and Maybe.all which can correctly handle both array and tuple types. To support this change, it now accepts arrays or tuples directly, and the variadic/spread arguments to all have been replaced with taking an array or tuple directly. While tuple and all are unchanged, they are also deprecated (see below).
importMaybe,{arrayTranspose,just,nothing}from'true-myth/maybe';// arraystypeArrayResult=Maybe<Array<string|number>>;letmixedArray=[just("hello"),nothing<number>()];letmixedArrayResult: ArrayResult=arrayTranspose(arrayOfMaybes);letallJustArray=[just("hello"),just(12)];letallJustArrayResult: ArrayResult=arrayTranspose(allJustArray);// Tuples now work with `arrayTranspose` as well.typeTuple=[Maybe<number>,Maybe<string>];typeTupleResult=Maybe<[number,string]>;letmixedTuple: Tuple=[just(12),just("hi")];letmixedTupleResult: TupleResult=arrayTranspose(mixedTuple);
Maybe.transpose and Result.transpose: for when you have a Maybe<Result<T, E>> or a Result<Maybe<T>, E> and need to invert them.
Note: these are standalone functions, not methods, because TypeScript
does not support conditionally supplying a method only for one specific type
parameterization.
🟥 Deprecated
Maybe.tuple and Maybe.all are deprecated in favor of Maybe.arrayTranspose now correctly handles both arrays and tuples. They will be removed not earlier than 6.0.0 (timeline not decided, but not sooner than when Node 12 LTS reaches end of life on April 30, 2022).
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
💥 Changed
The top-level namespace-style export has been removed. If you were relying on the static members to be present when doing
import Maybe from 'true-myth/maybe'
orimport Result from 'true-myth/result';
, you can replace them withimport * as Maybe from 'true-myth/maybe';
orimport * as Result from 'true-myth/result';
. This should make for much better tree-shaking with bundlers like Rollup, which can see “through” a namespace import in a way they cannot with a manually-created namespace object. Where you want to maintain the type and namespace imports, you can do this:In general, though, you should prefer to simply import the named functions instead:
There are no longer separate classes for
Just
,Nothing
,Ok
, andErr
. This substantially reduces the size of the library, and should hopefully improve browsers' ability to optimize code using these, since there is now only one class in each case:Maybe
andResult
. The public API for the classes is unchanged, but if you relied oninstanceof
checks against those classes anywhere, those checks will no longer work.The exported
Variant
types are now frozen, constant objects, not TypeScriptenum
s. This should not break anyone, since the only difference in observable behavior between anenum
and aconst
is the ability to do a “reverse lookup” on anenum
—but since the field names and their values are identical, this just means shipping less, and faster, code.The
isJust
,isNothing
,isOk
, andisErr
methods have been converted to getters. This makes them muchmore immediately useful in contexts where invoking a function is annoying, for any reason—for example, in Ember templates.We no longer publish CommonJS modules, only ES Modules.
Dropped support for Node versions earlier than Node 12 LTS.
Support for versions of TypeScript before 4.0 have been removed, to enable the type-safe re-implementation of
Maybe.all
.The
MaybeShape
andResultShape
interfaces are no longer exported. These were never intended for public reimplementation, and there is accordingly no value in their continuing to be public.A number of aliases (originally designed to make migration from e.g. Folktale easier) have been removed:
cata
: usematch
chain
andflatMap
: useandThen
maybeify
andtransmogrify
: usewrapReturn
unsafelyGet
,unsafeGet
, andunsafelyUnwrap
: use.isJust
/.isOk
then.value
unsafelyGetErr
andunsafelyUnwrapErr
: use.isErr
then.error
getOr
: useunwrapOr
getOrElse
: useunwrapOrElse
fromNullable
andmaybe
:Maybe
and use its static constructorMaybe.of
Maybe.of
of
and alias it as you like⭐ Added
We introduced a new
Maybe.transposeArray
, which is a type-safe, renamed, merged version ofMaybe.tuple
andMaybe.all
which can correctly handle both array and tuple types. To support this change, it now accepts arrays or tuples directly, and the variadic/spread arguments toall
have been replaced with taking an array or tuple directly. Whiletuple
andall
are unchanged, they are also deprecated (see below).Before:
After:
Maybe.transpose
andResult.transpose
: for when you have aMaybe<Result<T, E>>
or aResult<Maybe<T>, E>
and need to invert them.See the docs for further details!
Note: these are standalone functions, not methods, because TypeScript
does not support conditionally supplying a method only for one specific type
parameterization.
🟥 Deprecated
Maybe.tuple
andMaybe.all
are deprecated in favor ofMaybe.arrayTranspose
now correctly handles both arrays and tuples. They will be removed not earlier than 6.0.0 (timeline not decided, but not sooner than when Node 12 LTS reaches end of life on April 30, 2022).Full change list
Maybe.all
implementation by @chriskrycho in [breaking] type-safeMaybe.all
implementation #88*Shape
interface exports by @chriskrycho in [breaking] remove*Shape
interface exports #93any
from the codebase by @chriskrycho in Remove all uses ofany
from the codebase #94engines
, fix authors/contributors by @chriskrycho in Require Node 12 || 14+ inengines
, fix authors/contributors #121ap
docs about currying by @chriskrycho in Correct theap
docs about currying #216transpose
handling by @chriskrycho in Improvetranspose
handling #219New Contributors
Full Changelog: v4.1.1...v5.0.0
This discussion was created from the release ES Modules *and* a much smaller bundle.
Beta Was this translation helpful? Give feedback.
All reactions