-
Notifications
You must be signed in to change notification settings - Fork 53
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
Add support for .at/.atOrElse on Options, .atOrElse on Map, and .apply as an alias for .using #57
Conversation
def atOrElse(fa: F[T], default: => T)(f: T => T): F[T] | ||
} | ||
|
||
implicit class QuicklensSingleAt[F[_], T](t: F[T])(implicit f: QuicklensSingleAtFunctor[F, T]) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Open to a better name here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, I feel the same need for a better name, but can't come up with anything. So single it is :)
@@ -10,6 +10,12 @@ class ModifyMapAtTest extends AnyFlatSpec with Matchers { | |||
modify(m1)(_.at("K1").a5.name).using(duplicate) should be(m1dup) | |||
} | |||
|
|||
it should "modify a non-nested map with atOrElse" in { | |||
modify(m1)(_.atOrElse("K1", A4(A5("d4"))).a5.name).using(duplicate) should be(m1dup) | |||
modify(m1)(_.atOrElse("K1", ???).a5.name).using(duplicate) should be(m1dup) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Testing that we don't call the default if we don't have to.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 good idea
Thanks for the PR! The project is maintained and PRs are always welcome :)
Looking through the features, I think we are also missing a |
|
Why would
Maps are another thing, we currently have |
Yeah, all I meant was that I'd like to throw in one last push for this
.modify(_.eventsReversed)(event :: _)
.modify(_.logProb)(_ + event.score)
.modify(_.cost)(_ + event.cost) is better than copy(
event :: eventsReversed,
logProb = logProb + event.score,
cost = cost + event.cost,
) but they don't like this
.modify(_.eventsReversed)
.using(event :: _)
.modify(_.logProb)
.using(_ + event.score)
.modify(_.cost)
.using(_ + event.cost) We can use |
Ok, you've convinced me on We can also try with |
@@ -56,7 +56,7 @@ import com.softwaremill.quicklens._ | |||
|
|||
case class Street(name: String) | |||
case class Address(street: Option[Street]) | |||
case class Person(addresses: List[Address]) | |||
case class Person(addresses: Seq[Address]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was worried when I first read the docs that you had to use List
s, so I changed all the types to Seq
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, let's mention Seq
s as the supported collections, but keep List
s in the examples. That's the most common collection :)
@@ -84,33 +84,55 @@ person | |||
.using(_.toUpperCase) | |||
```` | |||
|
|||
**Modify specific sequence elements using .at:** | |||
**Modify specific elements in an option/sequence/map using .at:** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Merged these into one section.
@adamw this is ready for another look. I updated the docs and added a disclaimer on |
Great PR - thanks! Released in 1.5.0 |
Hi,
I just stumbled upon your awesome tool while building something very similar myself. I really like the way you have things set up. I wanted to add a few things and wasn't quite sure if this repo was still being actively maintained. I know it's bad practice to put multiple things in a single PR, but I wanted to get tentative approval before sending you multiple PRs. This PR adds a couple of things:
we get
.at
on Option, which acts like the otherat
methods in that it crashes if the Option is None.One thing I had done the with the macro I wrote was directly allow calls to
Option.get
,Option.getOrElse
, andMap.getOrElse
(and alsoMap.apply
, but you already have that withat
). I thought adding new methods was more in keeping with your approach and also required slightly less code. Curious to hear what you think!Kind of addresses #39.
(I will also rebase before merging).