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

addLeft/addRight convenience methods for Iors? #3689

Closed
keirlawson opened this issue Nov 20, 2020 · 1 comment · Fixed by #3698
Closed

addLeft/addRight convenience methods for Iors? #3689

keirlawson opened this issue Nov 20, 2020 · 1 comment · Fixed by #3698

Comments

@keirlawson
Copy link
Contributor

Whilst contributing to a cats-based codebase that makes extensive use of Iors (typelevel/grackle#96) I found myself needing a "addLeft" function, which given an Ior would either combine the new value with the existing LHS or in the case where it was a Right, turn it in to a Both with the new value on the left, ie

  def addLeft[A: Semigroup, B](ior: Ior[A,B], a: A): Ior[A, B] = ior match {
    case Ior.Right(r) => Both(a, r)
    case Both(l, r) => Both(l combine a, r)
    case Ior.Left(l) => Ior.left(l combine a)
  }

Would this be something that would make sense to include within Cats itself?

@keirlawson keirlawson changed the title addLeft/addRight convience methoids for Iors? addLeft/addRight convenience methoids for Iors? Nov 20, 2020
@LukaJCB
Copy link
Member

LukaJCB commented Nov 22, 2020

Sounds like a good addition to me :)

@keirlawson keirlawson changed the title addLeft/addRight convenience methoids for Iors? addLeft/addRight convenience methods for Iors? Nov 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants