Skip to content

Instantly share code, notes, and snippets.

@kryptt
Created August 17, 2020 10:24
Show Gist options
  • Save kryptt/58d1b9efba7e0a00dadd3a2e4bf1b186 to your computer and use it in GitHub Desktop.
Save kryptt/58d1b9efba7e0a00dadd3a2e4bf1b186 to your computer and use it in GitHub Desktop.
// 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