-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #57 from adampauls/master
Add support for .at/.atOrElse on Options, .atOrElse on Map, and .apply as an alias for .using
- Loading branch information
Showing
9 changed files
with
173 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
quicklens/src/test/scala/com/softwaremill/quicklens/ModifyOptionAtOrElseTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.softwaremill.quicklens | ||
|
||
import org.scalatest.flatspec.AnyFlatSpec | ||
import org.scalatest.matchers.should.Matchers | ||
|
||
class ModifyOptionAtOrElseTest extends AnyFlatSpec with Matchers { | ||
|
||
it should "modify a Some" in { | ||
modify(Option(1))(_.atOrElse(3)).using(_ + 1) should be(Option(2)) | ||
} | ||
|
||
it should "modify a None with default" in { | ||
modify(None: Option[Int])(_.atOrElse(3)).using(_ + 1) should be(Option(4)) | ||
} | ||
|
||
it should "modify a Option in a case class hierarchy" in { | ||
case class Foo(a: Int) | ||
case class Bar(foo: Foo) | ||
case class BarOpt(maybeBar: Option[Bar]) | ||
case class BazOpt(barOpt: BarOpt) | ||
modify(BazOpt(BarOpt(None)))(_.barOpt.maybeBar.atOrElse(Bar(Foo(5))).foo.a).using(_ + 1) should be( | ||
BazOpt(BarOpt(Some(Bar(Foo(6))))) | ||
) | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
quicklens/src/test/scala/com/softwaremill/quicklens/ModifyOptionAtTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.softwaremill.quicklens | ||
|
||
import java.util.NoSuchElementException | ||
|
||
import org.scalatest.flatspec.AnyFlatSpec | ||
import org.scalatest.matchers.should.Matchers | ||
|
||
class ModifyOptionAtTest extends AnyFlatSpec with Matchers { | ||
|
||
it should "modify a Option with case class item" in { | ||
modify(Option(1))(_.at).using(_ + 1) should be(Option(2)) | ||
} | ||
|
||
it should "modify a Option in a case class hierarchy" in { | ||
case class Foo(a: Int) | ||
case class Bar(foo: Foo) | ||
case class BarOpt(maybeBar: Option[Bar]) | ||
case class BazOpt(barOpt: BarOpt) | ||
modify(BazOpt(BarOpt(Some(Bar(Foo(4))))))(_.barOpt.maybeBar.at.foo.a).using(_ + 1) should be( | ||
BazOpt(BarOpt(Some(Bar(Foo(5))))) | ||
) | ||
} | ||
|
||
it should "crashes on missing key" in { | ||
an[NoSuchElementException] should be thrownBy modify(None: Option[Int])(_.at).using(_ + 1) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters