Skip to content

Instantly share code, notes, and snippets.

@chetkhatri
Created December 20, 2019 22:32
Show Gist options
  • Save chetkhatri/9a9db80d52c1b8e19aae31945cd7520f to your computer and use it in GitHub Desktop.
Save chetkhatri/9a9db80d52c1b8e19aae31945cd7520f to your computer and use it in GitHub Desktop.
private def monotonizeCommitTimestamps[T <: CommitMarker](commits: Array[T]): Array[T] = {
commits.tail.scanLeft(commits.head)((prev, current) => {
assert(prev.getVersion < current.getVersion, "Unordered commits provided.")
if (prev.getTimestamp >= current.getTimestamp) {
logWarning(s"Found Delta commit ${prev.getVersion} with a timestamp ${prev.getTimestamp} " +
s"which is greater than the next commit timestamp ${current.getTimestamp}.")
current.withTimestamp(prev.getTimestamp + 1).asInstanceOf[T]
}
else {
current
}
})
}
@chetkhatri
Copy link
Author

this gives an error,

<pastie>:13: error: type mismatch;
 found   : scala.collection.mutable.ArraySeq[T]
 required: Array[T]
    commits.tail.scanLeft(commits.head)((prev, current) => {

is there anyway without changing the return type actual I can return Array[T]?

@arosien
Copy link

arosien commented Dec 20, 2019

does changing the signature to private def monotonizeCommitTimestamps[T <: CommitMarker : scala.reflect.ClassTag](commits: Array[T]): Array[T] compile?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment