sanctuary-js / sanctuary-def

Run-time type system for JavaScript
MIT License
294 stars 23 forks source link

allow extractors to return any foldable structure #256

Closed davidchambers closed 5 years ago

davidchambers commented 5 years ago

I realized while working on sanctuary-list that we need not require an array of values specifically. Many algebraic data types are foldable, so in some cases the identity function should be able to serve as an extractor function.

I tried generalizing the code to avoid using toArray anywhere, but this proved impractical due to uses of Z.chain with functions that always return arrays. The solution is to compose each of the extractors with toArray, necessitating very few internal changes.