Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
map
allows you to transform the expression to another value, and then run that new value against another matcher.I find
map
to be most useful when combined withsatisfyAllOf
, as a kind of "fuzzy equals" matcher. Or, when you only care about some parts of a value matching but not other.In fact, without composing
map
withsatisfyAllOf
, I don't really see the point ofmap
at all. After allexpect(foo.property).to(equal(1))
is much more readable and succinct thanexpect(foo).to(map(\.property, equal(1))))
.I also added some guidance for when to use
map
. In my view,map
sits in a weird case where you want to check multiple multiple properties of a value at the same time (perhaps as part of atoEventually
-style matcher), but don't want the value to conform to Equatable, nor do you check that value enough to write a custom matcher for it.Some trivia: Originally, this matcher was named
lens
, from the functional programming concept. However, I changed it tomap
which is both closer to how it's actually used/written, and much more idiomatic to swift.Checklist - While not every PR needs it, new features should consider this list: