Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[extras-cats] Add innerFind, innerFilterOrElse, innerExists, innerForall, innerContains, innerCollectFirst, innerOrElse and innerOrElseF extension methods to F[Either[A, B]] #362

Closed
kevin-lee opened this issue Mar 11, 2023 · 0 comments · Fixed by #363
Assignees
Labels
task Task
Milestone

Comments

@kevin-lee
Copy link
Owner

kevin-lee commented Mar 11, 2023

Task

Summary

[extras-cats] Add innerFind, innerFilterOrElse, innerExists, innerForall, innerContains, innerCollectFirst, innerOrElse and innerOrElseF extension methods to F[Either[A, B]]

Project Details

Version: 0.35.0

Description

  • innerFind

    val feab: F[Either[A, B]] = ...
    feab.innerFind(B => Boolean): F[Option[B]]
    val feab: IO[Either[String, Int]] = IO(Right(1))
    // IO[Either[String, Int]] = IO(Right(1))
    feab.innerFind(_ > 0)
    // IO[Option[Int]] = IO(Some(1))
    feab.innerFind(_ > 1)
    // IO[Option[Int]] = IO(None)
  • innerFilterOrElse

    val feab: F[Either[A, B]] = ...
    feab.innerFilterOrElse[C >: A](B => Boolean, C): F[Either[C, B]]
    val feab: IO[Either[String, Int]] = IO(Right(1))
    // IO[Either[String, Int]] = IO(Right(1))
    feab.innerFilterOrElse(_ > 0, "Error")
    // IO[Either[String, Int]] = IO(Right(1))
    feab.innerFilterOrElse(_ > 1, "Error")
    // IO[Either[String, Int]] = IO(Left("Error"))
  • innerExists

    val feab: F[Either[A, B]] = ...
    feab.innerExists(B => Boolean): F[Boolean]
    val feab: IO[Either[String, Int]] = IO(Right(1))
    // IO[Either[String, Int]] = IO(Right(1))
    feab.innerExists(_ > 0)
    // IO[Boolean] = IO(true)
    feab.innerExists(_ > 1)
    // IO[Boolean] = IO(false)
  • innerForall

    val feab: F[Either[A, B]] = ...
    feab.innerForall(B => Boolean): F[Boolean]
    val feab: IO[Either[String, Int]] = IO(Right(1))
    // IO[Either[String, Int]] = IO(Right(1))
    feab.innerForall(_ > 0)
    // IO[Boolean] = IO(true)
    feab.innerForall(_ > 1)
    // IO[Boolean] = IO(false)
    
    val feab2: IO[Either[String, Int]] = IO(Left("Error"))
    // IO[Either[String, Int]] = IO(Left("Error"))
    feab2.innerForall(_ > 1)
    // IO[Boolean] = IO(true)
  • innerContains

    val feab: F[Either[A, B]] = ...
    feab.innerContains(B): F[Boolean]
    val feab: IO[Either[String, Int]] = IO(Right(1))
    // IO[Either[String, Int]] = IO(Right(1))
    feab.innerContains(1)
    // IO[Boolean] = IO(true)
    feab.innerContains(0)
    // IO[Boolean] = IO(false)
    
    val feab2: IO[Either[String, Int]] = IO(Left("Error"))
    // IO[Either[String, Int]] = IO(Left("Error"))
    feab2.innerContains(1)
    // IO[Boolean] = IO(false)
  • innerCollectFirst

    val feab: F[Either[A, B]] = ...
    feab.innerCollectFirst[D](PartialFunction[B, D]): F[Option[D]]
    val feab: IO[Either[String, Int]] = IO(Right(1))
    // IO[Either[String, Int]] = IO(Right(1))
    feab.innerCollectFirst {
      case 1 => 0
      case 2 => 999
    }
    // IO[Option[Int]] = IO(Some(0))
    
    val feab2: IO[Either[String, Int]] = IO(Right(2))
    // IO[Either[String, Int]] = IO(Right(2))
    feab2.innerCollectFirst {
      case 1 => 0
      case 2 => 999
    }
    // IO[Option[Int]] = IO(Some(999))
    
    val feab3: IO[Either[String, Int]] = IO(Right(3))
    // IO[Either[String, Int]] = IO(Right(3))
    feab3.innerCollectFirst {
      case 1 => 0
      case 2 => 999
    }
    // IO[Option[Int]] = IO(None)
    
    val feab4: IO[Either[String, Int]] = IO(Left("Error"))
    // IO[Either[String, Int]] = IO(Left("Error"))
    feab4.innerCollectFirst {
      case 1 => 0
      case 2 => 999
    }
    // IO[Option[Int]] = IO(None)
  • innerOrElse

    val feab: F[Either[A, B]] = ...
    feab.innerOrElse[C >: A, D >: B](=> Either[C, D]): F[Either[C, D]]
    val feab: IO[Either[String, Int]] = IO(Right(1))
    // IO[Either[String, Int]] = IO(Right(1))
    feab.innerOrElse(0.asRight[String])
    // IO[Option[Int]] = IO(Some(1))
    
    val feab2: IO[Either[String, Int]] = IO(Left("Error"))
    // IO[Either[String, Int]] = IO(Left("Error"))
    feab2.innerOrElse(0.asRight[String])
    // IO[Option[Int]] = IO(Some(0))
  • innerOrElseF

    val feab: F[Either[A, B]] = ...
    feab.innerOrElseF[C >: A, D >: B](=> F[Either[C, D]]): F[Either[C, D]]
    val feab: IO[Either[String, Int]] = IO(Right(1))
    // IO[Either[String, Int]] = IO(Right(1))
    feab.innerOrElseF(IO.pure(0.asRight[String]))
    // IO[Option[Int]] = IO(Some(1))
    
    val feab2: IO[Either[String, Int]] = IO(Left("Error"))
    // IO[Either[String, Int]] = IO(Left("Error"))
    feab2.innerOrElseF(IO.pure(0.asRight[String]))
    // IO[Option[Int]] = IO(Some(0))
@kevin-lee kevin-lee added the task Task label Mar 11, 2023
@kevin-lee kevin-lee added this to the milestone37 milestone Mar 11, 2023
@kevin-lee kevin-lee self-assigned this Mar 11, 2023
kevin-lee added a commit that referenced this issue Mar 11, 2023
…-to-FEitherAB

Close #362 - [`extras-cats`] Add `innerFind`, `innerFilterOrElse`, `innerExists`, `innerForall`, `innerContains`, `innerCollectFirst`, `innerOrElse` and `innerOrElseF` extension methods to `F[Either[A, B]]`
kevin-lee added a commit that referenced this issue Mar 11, 2023
Issue #362 - Fix type parameter of `innerCollectFirst` for `F[Either[A, B]]`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment