-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add RandomId helper * Remove unused imports * fix missing .flatten method in TestFrameworkApi
- Loading branch information
1 parent
85888b9
commit b957602
Showing
5 changed files
with
53 additions
and
2 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
core/src/main/scala/com/evolutiongaming/catshelper/RandomId.scala
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.evolutiongaming.catshelper | ||
|
||
import cats.kernel.Eq | ||
import cats.{Order, Show} | ||
|
||
final case class RandomId(value: String) extends AnyVal { | ||
override def toString = value | ||
} | ||
|
||
object RandomId { | ||
implicit val eqRandomId: Eq[RandomId] = Eq.fromUniversalEquals | ||
|
||
implicit val showRandomId: Show[RandomId] = Show.fromToString | ||
|
||
implicit val orderingRandomId: Ordering[RandomId] = Ordering.by(_.value ) | ||
|
||
implicit val orderRandomId: Order[RandomId] = Order.fromOrdering | ||
} |
19 changes: 19 additions & 0 deletions
19
core/src/main/scala/com/evolutiongaming/catshelper/RandomIdOf.scala
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.evolutiongaming.catshelper | ||
|
||
import java.util.UUID | ||
|
||
import cats.effect.Sync | ||
|
||
trait RandomIdOf[F[_]] { | ||
def apply: F[RandomId] | ||
} | ||
|
||
object RandomIdOf { | ||
|
||
def apply[F[_]](implicit fa: RandomIdOf[F]): RandomIdOf[F] = fa | ||
|
||
def uuid[F[_] : Sync]: RandomIdOf[F] = new RandomIdOf[F] { | ||
|
||
def apply = Sync[F].delay { RandomId(UUID.randomUUID().toString) } | ||
} | ||
} |
1 change: 0 additions & 1 deletion
1
core/src/test/scala/com/evolutiongaming/catshelper/CatsHelperSpec.scala
This file contains 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
16 changes: 16 additions & 0 deletions
16
core/src/test/scala/com/evolutiongaming/catshelper/RandomIdSpec.scala
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.evolutiongaming.catshelper | ||
|
||
import cats.effect.IO | ||
import com.evolutiongaming.catshelper.IOSuite._ | ||
import org.scalatest.funsuite.AsyncFunSuite | ||
import org.scalatest.matchers.should.Matchers | ||
|
||
class RandomIdSpec extends AsyncFunSuite with Matchers { | ||
test("uuid apply") { | ||
RandomIdOf | ||
.uuid[IO] | ||
.apply | ||
.map { _.value should not be empty } | ||
.run() | ||
} | ||
} |
This file contains 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