Last active
January 20, 2020 05:42
-
-
Save emmettna/1f1f814c275f754837477b53fe3f799d to your computer and use it in GitHub Desktop.
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
import cats.Applicative | |
import cats.effect.concurrent.Ref | |
import cats.implicits._ | |
import cats.effect._ | |
class InMemorySimpleCrud[F[_]: Applicative](ref: Ref[F, Map[String, Human]]) | |
extends SimpleCrud.Service[F] { | |
override def add(human: Human): F[Unit] = | |
ref.update(_.updated(human.name, human)) | |
override def find(name: String): F[Option[Human]] = | |
ref.get.map_.get(name) | |
} | |
object InMemorySimpleCrud { | |
def apply[F[_]: Applicative](implicit FF: Sync[F]): InMemorySimpleCrud[F] = | |
new InMemorySimpleCrud[F](Ref.unsafe[F, Map[String, Human]](Map[String, OrderHistory]().empty)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment