Permalink
Browse files

Replacing a few util functions with equivalent copies from base

  • Loading branch information...
NathanHowell committed Apr 27, 2012
1 parent 1fbc2c1 commit 03ba62d604d72a5b60eae0f0d5895ac9ee020095
Showing with 15 additions and 15 deletions.
  1. +15 −15 core/src/Visi/Util.hs
View
@@ -1,9 +1,13 @@
+{-# LANGUAGE FlexibleInstances #-}
+{-# LANGUAGE TypeSynonymInstances #-}
+
module Visi.Util (flatten, Stringable, VisiError(TypeError, ParsingError, DefaultError), ThrowsError,
passthru, listify, justFunc, vtrace, justOr, (|-), unsafeRandom,
buildMessageQueue, intHash, hexHash,
runOnThread) where
import Control.Monad.Error
+import Control.Monad.Instances ()
import Text.Parsec
import Debug.Trace
import System.IO.Unsafe
@@ -12,6 +16,7 @@ import qualified Data.Map as Map
import System.IO.Unsafe
import Control.Concurrent
import Data.IORef
+import Data.Maybe (fromMaybe, maybeToList)
import Data.Digest.Pure.SHA
import qualified Data.Text as T
import Data.ByteString.Lazy.UTF8
@@ -76,23 +81,19 @@ instance Show VisiError where show = showError
instance Error VisiError where
noMsg = DefaultError "An error has occurred"
strMsg = DefaultError
-
-justOr thing err = case thing of
- (Just v) -> {-return-} v
- _ -> err
-
--- | Turn a Maybe into a List of 0 or 1 element
-listify (Just a) = [a]
-listify _ = []
+justOr :: Maybe a -> a -> a
+justOr thing err = fromMaybe err thing
-passthru x = x
+-- | Turn a Maybe into a List of 0 or 1 element
+listify :: Maybe a -> [a]
+listify = maybeToList
-justFunc val maybe func =
- case maybe of
- Just x -> func x
- _ -> val
+passthru :: a -> a
+passthru = id
+justFunc :: b -> Maybe a -> (a -> b) -> b
+justFunc val m func = maybe val func m
-- | Build a non-blocking message queue and associated
-- | place to pull values placed in the Queue. Basically,
@@ -162,5 +163,4 @@ instance Stringable B.ByteString where
(|-) :: Either b a -> (a -> Either b c) -> Either b c
-(Right a) |- f = f a
-(Left b) |- _ = Left b
+(|-) = (>>=)

0 comments on commit 03ba62d

Please sign in to comment.