Skip to content

Add Priority / OrElse implicit search helper #2446

@alexandru

Description

@alexandru

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions