Skip to content

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

Description

@Trequetrum

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).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions