typelevel / typelevel/cats

`ap` ordering is inconsistent

Open
#2,172 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Scala
Stars
5.5k
Forks
1.2k
Avg merge
2d 10h
Merged PRs (30d)
5

Description

In Apply, ap is defined like so:

def ap[A, B](ff: F[A => B])(fa: F[A]): F[B]

If we're using the generated typeclass syntax, that means user code looks like function.ap(value).

Unfortunately, when ap is explicitly defined, it's almost always defined the opposite way. For example, on Validated:

def ap[EE >: E, B](f: Validated[EE, A => B])

This gives us usage code like value.ap(function). Knowing which ordering to expect is pretty confusing: it varies depending on the data type involved and whether or not we're working with it in a generic context.

I guess since we're at 1.0 we probably can't just go and fix it, but we might be able to define an alias that's used more consistently. (ap has always felt like a bit of an odd name to me... cats usually sticks to full words for methods like this.) i have some preference for the second form: it keeps the function on the right like map and flatMap, and the type inference is better.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the Apply typeclass and the explicit ap definition on Validated, then inspect how generated typeclass syntax exposes the method. Decide whether a compatible alias or another API change can resolve the ordering mismatch without breaking existing usage. Done would require an agreed design and consistent behavior across the affected APIs.

Written by the indexing model from the issue text.

Assessment

Tech stack
scala
Domain
developer-experience
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.