functional programming - Scala combine Seq of Timestamps -


hello i'm learning scala , have seq of object of following case class:

case class historycounter(time: datetime, counter:int) 

now combine value of counter based on timestamp time. sum of counters time on same day or same week.

how can this? 1 of collection functions fold or map capable of doing this?

if had list of these case classes called list, 1 way so:

  val counts =      list.groupby(_.time).map{       case (k, v) => (k, v.map(_.counter).sum)     } 

or more succinctly:

list.groupby(_.time).mapvalues(_.map(_.counter).sum)  

Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -