- .expect(msg) for both
Maybe
andResult
now wrap their payload innew Error()
instead of just throwing the payload directly.
2016-12-08
- Add Maybe.prototype.filter(fn) for chaining in conditionals to payload processing
2016-05-31
options
is now a reserved key that can't be used as a union member.
2016-03-23
Version 13 introduces a bunch of breaking changes, without deprecation warnings. Version 12 is still stable, so if you depend on stuff that's changing, you don't have to upgrade.
The changes are based off of close to half a year of full-time work building OpenRide with lots of our data wrapped up in Results instances. I think all of it takes results in a better direction.
-
Improved error reporting for "match called on non-member option"
UnionError: match called on a non-member option: '[A(42) from Union{ A, B }]'. Expected a member from { X, Y }'
-
UnionError
is gone. Results now just throwsError
s. -
Unions now only accept a single payload param.
- Unions now store that payload at
instance.payload
instead of as an array ininstance.data
. You really shouldn't be accessinginstance.data
directly anyway, but if you do, this change breaks that. - Implementing custom factories will also be broken -- please pass back the
raw
value
for payload instead of wrapping it in an Array.
- Unions now store that payload at
2016-01-29
Maybe.all
andPromise.all
should not flatten arrays in theirSome
s andOk
s. Now they don't.
2016-01-12
UnionError
should have passedinstanceof Error
checks. Now they do.
2016-01-12
- Return false for
Union({A:1}).A().equals(Immutable.Map())
instead of recursing infinitely.
2015-11-15
- Added static method
Maybe.nan
, likeMaybe.undefined
andMaybe.null
. - Added missing
.expect()
method toResult
.
-
The
_
symbol for match catch-all has been removed, after being deprecated since v0.10. The string'_'
is now reserved and cannot be used as a Union member option, and is the way to do catch-all matches going forward.Before:
import { Maybe, Some, _ } from 'results'; Maybe.match(Some(1), { Some: n => console.log('some', n), [_]: () => console.log('not some') });
Going forward:
import { Maybe, Some } from 'results'; Maybe.match(Some(1), { Some: n => console.log('some', n), _: () => console.log('not some') });
-
Err(payload).unwrap()
now throwspayload
instead of aUnionError
. -
.match
's_
catch-all handler now gets all the union option payloads applied to it instead of just passing in the union option itself. Passing in the union option was pretty useless, since you already have a ref to it if you can call.match
in the first place, and accessing it's.data
array was a little sketch.For Unions where all options accept the same kind of payload, accepting it as a argument to the catch-all handler can be pretty useful, even if it's maybe a little unsafe in general.
2015-11-13
- Added a static
.is(first, second)
function toUnion
for deep equality testing. - Added
.equals
proto method to all union option instances - Added
.hashCode
proto method to all union option instances (currently always returns42
). - These methods are equivalent to and compatible with ImmutableJS
- Union options instances'
.constructor
property is now a reference to its union'sOptionClass
, as it always should have been. Before this release it wasObject
. This shouldn't break anything unless you're doing really weird stuff :)
2015-11-02
- Added static methods
Result.try
,Maybe.undefined
, andMaybe.null
for plain-js interop. See the docs for details. - All errors thrown are now instances of
Result.Error
, which should still pass any(err instanceof Error)
checks, so hopefully nothing breaks :)
- Deprecating the
_
symbol has a breaking edge-case: A match from a union containing a member called"_"
that also has a wild-card member[_]
(the symbol), will always take the"_"
path instead of the catch-all symbol path. I'm fairly confident this affects zero people.
- The symbol exported from results as
_
is now deprecated. To do a catch-all match, just use a normal'_'
string key. For a cost of having one more reserved member name (never ever used?), catch-all matching (frequently used) is (back to) much more convenient.
- Improved the error message when a property in a
.match
object is not a function. It used to throw complaining that the prop was missing. Now it says that the prop is the wrong type.
2015-10-27
- Result.Ok(value) now returns
value
if it is an instance ofResult.OptionClass
, instead of unwrapping and rewrapping asOk
, and - Maybe.Some(value) now returns
value
if it's aMaybe.OptionClass
, instead of unwrapping and rewrapping asSome
. These changes are included to provide a way to "cast" arbitrary values to Result or Maybe, mirroringPromise.resolve(value)
.
2015-10-21
-
.match is no longer a proto method. It is now a static method living on the Union, like
.all
for Result and Maybe. It now takes two parameters: the first one being the instance to match against, and the second being the object defining the match handlers.import { Some, None, Maybe } from 'results'; // BEFORE (<= v0.7) Some(1).match({ Some: n => console.log('some!', n), None: () => console.log('none :(') }); // AFTER (>= v0.8) Maybe.match(Some(1), { Some: n => console.log('some!', n), None: () => console.log('none :(') });
2015-10-21
-
Removed the
.map
family of methods fromResult
andMaybe
-- use.andThen
(possibly chained with.or
or.orElse
) instead. -
Removed
.array
fromResult
andMaybe
proto. It came from rust's.iter
and.intoIter
, but it's not really useful in javascript... -
OptionClass
is now a reserved property forUnion
instances, so it can no longer be used as a key in Unions. -
The typescript declaration file is removed. It could be re-created and added to definitelyTyped or something, if anyone wants it.
-
Match's _ special-case catch-all key is removed. Instead,
results
now exports a symbol as_
that you can use as a computed key likeUnion({A: {}, B: {}, C: {}}).A().match({ A: () => console.log('A!'), [_]: () => console.log('something else...'), });
OptionClass
! Check which Union a value is coming from withinstanceof
Some
andOk
auto-promotion for the.and
and.or
families of methods, as well as.all
on the union instances.- Added toString methods. Some samples:
'[Union { A, B }]'
,'[[UnionOption A(1, 2) from Union { A }]]'
Maybe
's prototype grew.promiseOr
and.promiseOrElse
methods.Result
's prototype grew.promise
and.promiseErr
methods.- Converted source from typescript to es6 javascript, so we can use more es6 features, and remove ugly typescript hacks.
- Rewrote the readme with hopefully better content :) Still lots more to improve!
2015-10-17
- Only allow object Enum definition (
Enum({ONE: {}, TWO: {}, THREE: {}})
only; no moreEnum(['ONE', 'TWO', 'THREE'])
). - Enum option instance property
options
is now an Object instead of Array. - Throw
Error
instances instead of special internal error enums. It was a silly idea. - Remove sketchy faulty object typecheck for the Enum constructor. It's just not checked now. Whee.
- Add a
static
param to theEnum
function (afterproto
) for adding stuff to the Enum. - Use the new
static
param to add a.all
method toMaybe
andResult
, whose behaviour is close to that ofPromise.all
. Enum
renamed toUnion
!enum
is another thing in JavaScript, so this is less confusing.- Remove the
take
method fromSome/None
. .match
now throws for unrecognized keys in a provided options object.
- Fix typescript interfaces for ResultOption (props => methods)
- Annotate
match
param and return - Upgrade typescript version
Option
is now calledMaybe
, sinceOption
is a thing already.EnumOption.option
is now calledEnumOption.name
. thanks @mystor.EnumOption.args
is now calledEnumOption.data
. thanks @mystor.
- Use typescript. Mostly for docs at this point.
- Performance optimizations and stuff. Still not back to v0.3.0, but pretty lightweight and fast.
- Faster
EnumOption.match
function, thanks @mystor!
- Generalize
Result
andOption
to be built fromEnum
, and makeEnum
public - Breaking change -- errors are now
EnumOption
s
2015-03-14
- Rewrote constructors to be empty (or nearly-empty) functions with all the methods on the prototype. This required:
- Breaking change -- the
match
functionality is now a method just like all the other functions. See the updated examples in the readme.
2015-03-14
object-assign
is a real dependency, not a dev-dependency. It is now in the right place inpackage.json
, so this library should work...
2015-03-14
Err(errValue).orElse(fn)
now callsfn
witherrValue
, as it does in rust.- and,
Err(errValue).unwrapOrElse(fn)
does the same.
2015-03-06
Err(errValue).unwrap()
now throws withUNWRAP_ERR
anderrValue
, more closely matching Rust's behaviour (and mor useful).- Likewise,
Some(value).unwrapErr()
now throws withUNWRAPERR_SOME
andvalue
, and None().unwrap()
now throws withUNWRAP_NONE
and a message.