You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In Scala collections, the maxByOption returns the entire object:
scala> Seq((1, 2), (3, 4)).maxByOption(_._1)
val res0: Option[(Int, Int)] = Some((3,4)) // note: it returns (3, 4), not just 3
In ScalaSQL it doesn't. When you call maxByOption, the returned value is only the column. The reason is likely that there could be more than one row where the column reaches its maximum, so it's not obvious which one to choose.
I can see two ways to deal with this:
choose an arbitrary one, similar to what .sortBy(_.bla).take(1).singleOption would do
raise an error when there's more than one candidate. Note that this error can be avoided by setting a unique constraint on the column, but that is outside the scope of ScalaSQL.