Skip to content

Instances for Future #2334

Description

@ChristopherDavenport

Future is largely known to not be referentially transparent. As it starts execution immediately and caches the result.

While it may have been largely necessary for these instances to be in cats before cats-effect, with that solution coming in maturity it may be time for Future instances to be pushed to alleycats.

Imports

import scala.concurrent.Future
import scala.concurrent.ExecutionContext.Implicits.global
import cats.implicits._ 

Example 1 - Prints Once on the first line

val future1 : Future[Unit] = Future(println("I printed"))
val futureResult1 : Future[Unit] = (future1, future1).mapN(_ => ())

Example 2 - Prints twice on the second line

def future2: Future[Unit] = Future(println("I printed"))
val futureResult2 : Future[Unit] = (future2, future2).mapN(_ => ())

As you can see we have lost equational reasoning.

What are your thoughts on the future of Future?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions