Skip to content

Commit

Permalink
simplify Cache
Browse files Browse the repository at this point in the history
  • Loading branch information
janmasrovira committed Mar 20, 2024
1 parent 44a361e commit b311abd
Showing 1 changed file with 1 addition and 10 deletions.
11 changes: 1 addition & 10 deletions src/Juvix/Data/Effect/Cache.hs
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,7 @@ runCache ::
HashMap k v ->
Sem (Cache k v ': r) a ->
Sem r (HashMap k v, a)
runCache f c = reinterpret (runState c) $ \case
CacheLookup k -> gets @(HashMap k v) (^. at k)
CacheGet k -> do
mv <- gets @(HashMap k v) (^. at k)
case mv of
Just v -> return v
Nothing -> do
x :: v <- re f (f k)
modify' @(HashMap k v) (set (at k) (Just x))
return x
runCache f c = runState c . re f

evalCache ::
(Hashable k) =>
Expand Down

0 comments on commit b311abd

Please sign in to comment.