typelevel / typelevel/cats

Add Priority / OrElse implicit search helper

Open
#2,446 12 comments 4 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

Samples:

  1. https://github.com/typelevel/algebra/blob/master/core/src/main/scala/algebra/Priority.scala
  2. https://github.com/milessabin/shapeless/blob/master/core/src/main/scala/shapeless/orelse.scala

I've also encountered cases in which I wished to have this helper available with the Async / Concurrent type classes in Cats-Effect. So it would work like this:

  1. if a Concurrent instance is in scope, build a cancelable task via Concurrent.cancelable
  2. if only an Async instance is in scope, as a fallback, build an atomic task via Async.async

So this is a mechanism for optimizing the implementation in case a type class instance is available, or otherwise use the default. This optimization problem is also relevant for Haskell: https://stackoverflow.com/questions/44250854/use-specialized-implementation-if-a-class-instance-is-available

I think it's time we add something like this to cats-kernel.

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 linked Priority.scala and shapeless/orelse.scala examples, then compare the proposed Concurrent.cancelable and Async.async fallback behavior with the cats-kernel scope. Done would require an agreed API design for an implicit search helper and a clear decision on whether this belongs in cats-kernel.

Written by the indexing model from the issue text.

Assessment

Tech stack
scala
Domain
backend-api-design
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.