bow-swift / bow

🏹 Bow is a cross-platform library for Typed Functional Programming in Swift
https://bow-swift.io
Other
645 stars 32 forks source link

Bring consistency across HKT with partial application #565

Closed truizlop closed 4 years ago

truizlop commented 4 years ago

Goal

Currently, there is some dissonance between HKTs with one type argument and others with 2 or more arguments. Whereas the latter have their Partial versions, the former do not have this alias. This results in the following when instances for type classes need to be provided:

extension ForOption: Functor { ... }
extension EitherPartial: Functor { ... }

It seems weird not to have a single convention when implementing instances of type classes on the kind level, and having to remember that, for types with one type argument you need to use the For form, and for others the Partial form.

This PR unifies the convention by providing a Partial alias for types with a single type argument, so that the previous code still works, but the preferred way of doing it is:

extension OptionPartial: Functor { ... }
extension EitherPartial: Functor { ... }

This way, every time one needs to provide an instance for a type class in the kind level, only needs to remember that it is done in the Partial type.

Besides this, the PR updates the code of the modified files to make aesthetic changes:

Documentation has been updated accordingly.