Purify v0.16

November 7, 2020
Not sure what purify is? Check out the Getting Started page. Also check out the FAQ page!

This is a huge release with a lot of changes and I'm really exited! 0.16 will be the final 0.x version before the official 1.0.0 release, you can think of 0.16 as a Version 1 RC.

Breaking: Codec

  • Renamed GetInterface to GetType.
  • Running decode will not populate a field inside an object it's undefined, instead it will just leave it out.

Breaking: Either and Maybe

  • Removed internal __value property inside both Either and Maybe. It was not supposed to be used anyway so there shouldn't be any breakages.
  • Running Either#unsafeDecode used to throw a generic error if the value inside was Left. That error is still there, but if the value is an instance of Error, it will throw the value instead. This makes debugging and logging easier.

Breaking: EitherAsync and MaybeAsync

  • Removed liftPromise from both EitherAsync and MaybeAsync. With the addition of PromiseLike support this utility is just an alias for the normal constructors, making it redundant.
  • Since PromiseLike is now supported in both modules you should be using the special constructors liftEither, liftMaybe and fromPromise way less now.
    Because of that they are now static methods (e.g. to use run EitherAsync.liftEither or MaybeAsync.fromPromise)

Additions: EitherAsync and MaybeAsync (there are a lot)

  • Both EitherAsync and MaybeAsync now extend and support the PromiseLike interface. This means you can await them and you can interchange *Async and PromiseLike in most utility methods.
    This is a huge win for productivity and reducing boilerplate, I hope we get to see cool examples of how this helps people.
  • Both EitherAsync and MaybeAsync are now fantasy-land compatible.
  • Added static methods to EitherAsync - lefts, rights, sequence, liftEither, fromPromise.
  • Added instance methods to EitherAsync - swap, ifLeft, ifRight, bimap, join, ap, alt, extend, leftOrDefault, orDefault.
  • Added static methods to MaybeAsync - catMaybes, liftMaybe, fromPromise.
  • Added instance methods to EitherAsync - ifJust, ifNothing, join, ap, alt, extend, filter, orDefault.
  • EitherAsync now has a looser type definition for EitherAsync#chain as it will merge the two errors together in an union type instead of showing a compiler error if the error types are different.

Additions: Either and Maybe

  • Added static method to Maybe - isMaybe.
  • Added static methods to Either - isEither and sequence.
  • Either now has a looser type definition for Either#chain as it will merge the two errors together in an union type instead of showing a compiler error if the error types are different .
  • Either now has a runtime tag so that values are easier to debug (previously when you logged an Either you couldn't tell if it's Left or Right).

Additions: Codec

  • Added new codecs and combinators: nullable, enumeration, intersect.
  • Added a new property of each codec - schema, it returns a JSON Schema V6 of that codec so that you can reuse validation in non-JavaScript environments (tools, other languages etc.).
  • Added a new utility type, FromType, that helps with creating codecs based on existing types.
  • Added a new utility function - parseError, that takes an error string generated after running decode on a value and returns a meta object
    which you can use to create all kinds of stuff - from custom error reporters to recovery mechanisms.
  • If you use the maybe codec combinator inside a Codec.interface it will handle optional properties just like optional.

Additions: Other

  • Added two new methods to Tuple - some and every that act like the Array methods of the same name.
  • Added a new utility function to NonEmptyList - tail.

Bugfixes: Codec

  • Fixed a critical bug in oneOf that caused encoding to fail.