Last active
March 22, 2017 07:27
-
-
Save MansurAshraf/aafd363ba1a3a968ab81f9f9fe8c7d3d to your computer and use it in GitHub Desktop.
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
| class InMemoryStore[M[_]: Monad, K, V] extends Store[M, K, V] { | |
| override val monad: Monad[M] = implicitly[Monad[M]] | |
| private val map = new ConcurrentHashMap[K, V]() | |
| override def get(k: K): M[Option[V]] = monad.pure(Option(map.get(k))) | |
| override def put(kv: (K, V)): M[Unit] = monad.pure { | |
| val (k, v) = kv | |
| map.put(k, v) | |
| } | |
| override def close(): Unit = map.clear() | |
| } | |
| object InMemoryStore { | |
| def blocking[K, V]: BlockingStore[K, V] = new InMemoryStore[Try, K, V] with BlockingStore[K, V] | |
| def async[K, V]: AsyncStore[K, V] = new InMemoryStore[Future, K, V] with AsyncStore[K, V] | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment