Created
August 17, 2020 10:24
-
-
Save kryptt/58d1b9efba7e0a00dadd3a2e4bf1b186 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| // We can re-use a simple function that goes from Time to a new Time | |
| val adjustTime: DateTime => DateTime = ??? | |
| // With an appropriate traversal in scope we can apply the adjustTime function from this library to any incoming holder | |
| def adjustTimes[T](implicit T: Traversal[T, DateTime]): T => T = | |
| T.modify(adjustTime) | |
| // Again we can keep a concrete alternative to adjustTime, we just increment it by duration: | |
| def increaseTimeBy(duration: FiniteDuration): DateTime => DateTime = | |
| _.add(duration) | |
| // and re-use the same lense, to update the time on on transactions in a balance sheet adding to them a fixed amount. | |
| def increaseTimesBy[T](duration: FiniteDuration)(implicit T: Traversal[T, DateTime]: T => T = | |
| T.modify(increaseTimeBy(duration)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment