Skip to content

.maxByOption should return the entire row, not just the column #93

@mberndt123

Description

@mberndt123

Hi,

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:

  1. choose an arbitrary one, similar to what .sortBy(_.bla).take(1).singleOption would do
  2. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions