Skip to content

Commit

Permalink
Add evaluateWHNF and evaluateNF functions
Browse files Browse the repository at this point in the history
Also closes #38
  • Loading branch information
chshersh committed Apr 13, 2017
1 parent 036e312 commit 2dbf700
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Expand Up @@ -5,6 +5,8 @@
* Rewrite README tutorial.
* [#37](https://github.com/serokell/universum/issues/37):
Add generalized version of `readEither`.
* [#38](https://github.com/serokell/universum/issues/38):
Add `evaluateNF` and `evaluateWHNF`.

0.3
===
Expand Down
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -253,6 +253,8 @@ Finally, we can move to part describing what new cool features we bring with `un
* `using(Reader|State)[T]` functions as aliases for `flip run(Reader|State)[T]`.
* [`One` type class](https://github.com/serokell/universum/blob/master/src/Containers.hs#L473)
for creating singleton containers. Even monomorhpic like `Text`.
* `evaluateWHNF` and `evaluateNF` functions as clearer and lifted aliases for
`evaluate` and `evaluate . force`.

License
-------
Expand Down
23 changes: 17 additions & 6 deletions src/Universum.hs
Expand Up @@ -22,17 +22,19 @@ module Universum
, Buildable

-- * Useful standard unclassifed functions
, evaluateNF
, evaluateWHNF
, foreach
, guarded
, identity
, map
, uncons
, unsnoc
, pretty
, prettyL
, print
, readEither
, foreach
, guarded
, show
, uncons
, unsnoc

-- * Convenient type aliases
, LText
Expand Down Expand Up @@ -173,8 +175,9 @@ import Lens.Micro as X (Lens, Lens', Traversal, Traversa
(^?), _1, _2, _3, _4, _5)
import Lens.Micro.Mtl as X (preuse, preview, use, view)

-- For internal usage
import qualified Prelude as Prelude
-- For internal usage only
import qualified Control.Exception.Base (evaluate)
import qualified Prelude (print)
import qualified Text.Read (readEither)

-- | Type synonym for 'Data.Text.Lazy.Text'.
Expand Down Expand Up @@ -257,3 +260,11 @@ pretty = X.toStrict . prettyL
-- | Similar to 'pretty' but for 'LText'.
prettyL :: Buildable a => a -> LText
prettyL = toLazyText . build

-- | Lifted alias for 'Control.Exception.Base.evaluate' with clearer name.
evaluateWHNF :: MonadIO m => a -> m a
evaluateWHNF = liftIO . Control.Exception.Base.evaluate

-- | Alias for 'evaluateWHNF . force' with clearer name.
evaluateNF :: (X.NFData a, MonadIO m) => a -> m a
evaluateNF = evaluateWHNF . force

0 comments on commit 2dbf700

Please sign in to comment.