Purify v0.12

January 30, 2019
Not sure what purify is? Check out the Getting Started page. Not sure if you want to introduce purify as a dependency to your project? Check out the new FAQ page!

Before starting, I want to thank everyone that contributed to the project with bug reports, fixes and suggestions ⭐️.

MaybeAsync and EitherAsync

Dealing with asynchronous values was a huge pain point and I've spent a lot of time prototyping different solutions.
The general approach to error handling in imperative languages is to throw exceptions, which didn't fit into the functional nature of purify.
At the same time, TypeScript's type system made expressing functional patterns cumbersome, which didn't leave me with a lot of options.
Despite those challenges I believe the final APIs for MaybeAsync and EitherAsync turned out fairly elegant and easy to use, please let me know your opinion!

Complete rewrite

Put simply, the library had too many issues mainly because of the "single-class" implementation of the ADTs, which have since been rewritten into plain functions and objects.
This removed a whole class of errors (pun not intended), like a strange bug that prevented functions returning a Nothing to be annotated with the proper Maybe type (so strange I've filed an issue )
This change is completely under the hood, the public API remains the same.

Proper fantasy-land support

All data types provided by purify now include a proper implementation of the `constructor` property which points to the type representative.
As a bonus, there is also a Foldable instance for Tuple now!

Typeclasses - scrapped.
Id and Validation - removed.

Old versions of purify exported interfaces which were designed to serve the purpose of typeclasses.
There were numerous issues though - typeclasses like Monad could be easily represented as object methods, but functions like Applicative's `pure` (or `of` in fantasy-land) are meant to go on the type representative, not on the object. A Monad instance requires an Applicative instance which was unrepresentable in TypeScript's type system without resorting to techniques that don't fit into the "interfaces with generics" model. There's also the issues with typeclasses like Ord, Setoid and Semigroup which don't make much sense in JavaScript where you can compare all values.

All of these things led to the removal of typeclasses from the library. With that went the Id datatype which serves no need anymore.
Since typeclasses were also the justification for having folders in the library exports, now the folder structure is flat.
This means that imports like import { Maybe } from 'purify-ts/adts/Maybe are now just import { Maybe } from 'purify-ts/Maybe'.
The Validation module was removed for a completely different reason though - the API was just too limiting and ad-hoc, hopefully it will return soon in a better, more generic form.

New Maybe methods

The original focus for this release was better JS interop and before the implementation of MaybeAsync and EitherAsync took most of my time working on this project, two new methods were added to the Maybe data type.
  • Maybe#chainNullable - The same as Maybe#chain but for functions that return a nullable value instead of Maybe.
  • Maybe#extract - Now returns an undefined instead of null as undefined is used more often to reprent missing values.
  • Maybe#extractNullable - The new name of Maybe#extract from previous versions of purify

Other changes

  • There is now a "Guides" section for each data type which will hopefully include a lot of useful information in the near future. Stay tuned.
  • Docs are now part of the npm package, which means you should be getting more information in your editor during autocomplete.
  • Fixed bug where Just(null) would be treated as Nothing.