Assume I have:
case class JobID(i: Int):
@targetName("minus")
def -(other: JobID): Int = i - other.i
end JobID
case class Job( id: JobID,
start: Instant = ZeroInstant,
total: Duration = ZeroDuration
)
object JobIDOrdering extends Ordering[Job]:
override def compare(a: Job, b: Job): Int =
val byID = a.id - b.id
byID
val completed: SortedSet[Job] = SortedSet()(JobIDOrdering)
At some point in my code I hold 2 references to Job
with the same JobID
. One (job
) is external and the other an updated version of job:Job
stored in the completed
set. So my question is: how can I efficiency extract the updated instance inside the set using the “external” job
?
I came up with the following solution:
val updatedJob = completed.intersect(SortedSet(job)(JobIDOrdering)).head
but that seems too complex for such a simple goal. I find no “get” method. Am I missing something?
TIA