Created
March 5, 2020 17:54
-
-
Save Daenyth/9d7b0ffea1e5ec4f87ec2d63e038e2cc to your computer and use it in GitHub Desktop.
Shard `Long` values across N days
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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