Skip to content

Commit

Permalink
Utils: add dup; Thunk.Basic: further: define with a dup
Browse files Browse the repository at this point in the history
We saw that `further` does not even need to strictly pattern match on a thunk,
since the results of bothe matches would be the same, so we can skip matching.
  • Loading branch information
Anton-Latukha committed Mar 14, 2021
1 parent 7b6a081 commit c56b92e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
11 changes: 4 additions & 7 deletions src/Nix/Thunk/Basic.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ import Control.Monad.Catch ( MonadCatch(..)
)
import Nix.Thunk
import Nix.Var
import Nix.Utils ( bool )
import Nix.Utils ( bool
, dup
)

data Deferred m v = Computed v | Deferred (m v)
deriving (Functor, Foldable, Traversable)
Expand Down Expand Up @@ -115,12 +117,7 @@ instance (MonadBasicThunk m, MonadCatch m)
_ <-
atomicModifyVar
ref
(\ x ->
deferred
(const (x, x))
(const (x, x))
x
)
dup
pure t


Expand Down
6 changes: 6 additions & 0 deletions src/Nix/Utils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -283,3 +283,9 @@ for_ = flip traverse_
both :: (a -> b) -> (a, a) -> (b, b)
both f (x,y) = (f x, f y)
{-# inline both #-}


-- | Duplicates object into a tuple.
dup :: a -> (a, a)
dup x = (x, x)
{-# inline dup #-}

0 comments on commit c56b92e

Please sign in to comment.