Skip to content

Commit 5182637

Browse files
authored
Add instantiation of MeasureDuration from cats-helper instance (#260)
* Add implicit instantiation of MeasureDuration from cats-helper instance * Make conversion explicit * Add reverse conversion
1 parent 025666f commit 5182637

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

build.sbt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ lazy val smetrics = (project
4444
libraryDependencies ++= Seq(
4545
Cats.core,
4646
Cats.effect,
47+
`cats-helper` % Optional,
4748
`cats-helper` % Test,
4849
scalatest % Test),
4950
libraryDependencies ++= crossSettings(

smetrics/src/main/scala/com/evolutiongaming/smetrics/MeasureDuration.scala

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.evolutiongaming.smetrics
33
import cats.effect.Clock
44
import cats.implicits._
55
import cats.{Applicative, FlatMap, ~>}
6+
import com.evolutiongaming.catshelper
67

78
import scala.concurrent.duration._
89

@@ -29,6 +30,11 @@ object MeasureDuration {
2930
fromClock1(clock, FlatMap[F])
3031
}
3132

33+
def fromCatsHelper[F[_]](implicit csMeasureDuration: catshelper.MeasureDuration[F]): MeasureDuration[F] =
34+
new MeasureDuration[F] {
35+
override def start: F[F[FiniteDuration]] = csMeasureDuration.start
36+
}
37+
3238
implicit def fromClock1[F[_]: Clock: FlatMap]: MeasureDuration[F] = {
3339
val duration = for {
3440
duration <- Clock[F].monotonic
@@ -58,6 +64,10 @@ object MeasureDuration {
5864

5965
val start: G[G[FiniteDuration]] = f(self.start.map(f.apply))
6066
}
67+
68+
def toCatsHelper: catshelper.MeasureDuration[F] = new catshelper.MeasureDuration[F] {
69+
override def start: F[F[FiniteDuration]] = self.start
70+
}
6171
}
6272

63-
}
73+
}

0 commit comments

Comments
 (0)