-
Notifications
You must be signed in to change notification settings - Fork 12
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
PeriodSum tests and implementation #10
Conversation
override def subtractFrom(temporal: Temporal): Temporal = ??? | ||
for ( period <- periods; unit <- period.getUnits.asScala ) | ||
map.get(unit) match { | ||
case Some(value) => map.update( unit, value + period.get(unit)) |
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.
You can write this as map(unit) += period.get(unit). http://stackoverflow.com/questions/2662984/what-are-all-the-instances-of-syntactic-sugar-in-scala
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.
Unfortunately, that was my initial attempt, but I had to use the match keyword because there is nothing present in the map when it is instantiated, the map throws a NoSuchElementException because the key that we are trying to access has not been added yet.
Or do you mean line 80 specifically?
Corrected for PR comments |
for ( period <- periods; unit <- period.getUnits.asScala ) | ||
map.get(unit) match { | ||
case Some(value) => map(unit) += period.get(unit) | ||
case None => map += (unit -> period.get(unit)) |
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.
Sorry, should have caught this on my last pass. You can write this as map(unit) = period.get(unit).
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.
Scala doesn't seem to like that method of expressing the assignment, I get an error reading "Expression of type Long doesn't conform to expected type mutable.Map[TemporalUnit, Long]"
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.
Seems to work okay for me:
scala> var map = scala.collection.mutable.Map.empty[String, Long]
map: scala.collection.mutable.Map[String,Long] = Map()
scala> map("a") = 5
scala> map
res1: scala.collection.mutable.Map[String,Long] = Map(a -> 5)
I have no idea why it would not let me compile with that expression before - it should be fixed now! |
PeriodSum tests and implementation
Implements PeriodSums with functionality for PeriodSums that contain SimplePeriods and PeriodSums