Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consistency for Eq a / Ord a functions with suffix "By" #215

Open
Trequetrum opened this issue Apr 30, 2021 · 3 comments
Open

Consistency for Eq a / Ord a functions with suffix "By" #215

Trequetrum opened this issue Apr 30, 2021 · 3 comments
Labels
type: enhancement A new feature or addition.

Comments

@Trequetrum
Copy link

Trequetrum commented Apr 30, 2021

As I look through the API, I see a pretty consistent pattern of "You can rely on a typeclass for Eq/Ord or you can supply your own".

So if a type signature has forall a. Eq a => ..., there's often a version that removes this constraint and adds in a function like forall a. (a -> a -> Boolean) ...

There even seems like a pretty consistent naming pattern:

insert    & insertBy 
sort      & sortBy
group     & groupBy
groupAll  & groupAllBy
nub       & nubBy
nubEq     & nubByEq  <- Sort of a break from the pattern, but still
union     & unionBy
delete    & deleteBy
intersect & intersectBy

But it feels sort of arbitrary when some functions don't follow that pattern

For example: difference

I'd expect to see

difference :: forall a. Eq a => Array a -> Array a -> Array a
differenceBy :: forall a. (a -> a -> Boolean) -> Array a -> Array a -> Array a

The same holds for elem, notElem, elemIndex, and elemLastIndex, but these are covered by find >>> isJust, find >>> isNothing, findIndex, and findLastIndex. I understand a departure in naming pattern here since Eq a is replaced with (a -> Boolean) instead of (a -> a -> Boolean).

@JordanMartinez
Copy link
Contributor

I agree with this idea on principle. However, it does mean making breaking changes.

@Trequetrum
Copy link
Author

At least for difference and differenceBy, this wouldn't be a breaking change.

differenceBy doesn't exist yet.

@hdgarrood
Copy link
Contributor

I'd actually like to consider removing the Eq-based difference and replacing it with an Ord one, because the Eq one's performance is terrible. So that's a breaking change anyway. Adding a differenceBy sounds fine to me too. I'd prefer to leave elem, notElem, elemIndex, and elemLastIndex as they are though, personally.

@JordanMartinez JordanMartinez added the type: enhancement A new feature or addition. label Dec 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A new feature or addition.
Projects
None yet
Development

No branches or pull requests

3 participants