Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save emmettna/1f1f814c275f754837477b53fe3f799d to your computer and use it in GitHub Desktop.
Save emmettna/1f1f814c275f754837477b53fe3f799d to your computer and use it in GitHub Desktop.
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