sanctuary-js / sanctuary-def

Run-time type system for JavaScript
MIT License
293 stars 24 forks source link

combine _satisfactoryTypes and satisfactoryTypes #91

Closed davidchambers closed 8 years ago

davidchambers commented 8 years ago

While working on the patch that eventually became #90 I did some nice refactoring. In fact, at one point I was almost ready to submit a several-hundred-line patch to fix #16 when I realized I did not understand the changes well enough to describe them in a commit message. I revisited the patch and repeatedly reverted inessential changes until all that was left was a one-line change.

I still like the several-hundred-line refactoring, though, so I'm submitting it now for review.

Commit message:

Combining these functions necessitated replacing Error values with () -> Error thunks to avoid unnecessarily determining actual types.

Whereas _satisfactoryTypes took the "fixed" arguments and returned a function which took the "variable" arguments, the new function takes all its arguments at once. This is simpler and perhaps more efficient, but also less convenient due to the number of (recursive) call sites. To mitigate the problem this function and several others take name, constraints, and types as a single argument, a TypeInfo record.

Tip: Running document.location.search = '?w=' in your browser's console will remove some noise from the diff. This is GitHub's equivalent of Git's -w flag. :)