Skip to content

Instantly share code, notes, and snippets.

@Daenyth
Created March 5, 2020 17:54
Show Gist options
  • Save Daenyth/9d7b0ffea1e5ec4f87ec2d63e038e2cc to your computer and use it in GitHub Desktop.
Save Daenyth/9d7b0ffea1e5ec4f87ec2d63e038e2cc to your computer and use it in GitHub Desktop.
Shard `Long` values across N days
import cats._
import cats.implicits._
import cats.effect._
import scala.concurrent.duration._
object ModDate {
def epochDay[F[_]: Clock: Functor]: F[Long] =
Clock[F]
.realTime(SECONDS)
.map(FiniteDuration(_, SECONDS).toDays)
def modToday[F[_]: Clock: FlatMap](nDays: Int)(lst: List[Long]): F[List[Long]] =
epochDay[IO].flatMap { day =>
lst.filter { id =>
id % nDays.toLong === (day % nDays)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment