|
@@ -4,6 +4,9 @@ module Utils where
|
|
|
import Data.List
|
|
import Data.List
|
|
|
import Data.Char
|
|
import Data.Char
|
|
|
|
|
|
|
|
|
|
+ import Debug.Trace
|
|
|
|
|
+ import Text.Printf
|
|
|
|
|
+
|
|
|
(|>) = (&)
|
|
(|>) = (&)
|
|
|
|
|
|
|
|
(!?) :: [a] -> Int -> Maybe a
|
|
(!?) :: [a] -> Int -> Maybe a
|
|
@@ -217,3 +220,25 @@ module Utils where
|
|
|
flattenTupleList [(x, y)] = [x, y]
|
|
flattenTupleList [(x, y)] = [x, y]
|
|
|
flattenTupleList ((x, y):xs) = [x, y] ++ (flattenTupleList xs)
|
|
flattenTupleList ((x, y):xs) = [x, y] ++ (flattenTupleList xs)
|
|
|
|
|
|
|
|
|
|
+ mapi :: (Int -> a -> b) -> [a] -> [b]
|
|
|
|
|
+ mapi _ [] = []
|
|
|
|
|
+ mapi f l = go' l 0
|
|
|
|
|
+ where go' [] _ = []
|
|
|
|
|
+ go' [x] i = [f i x]
|
|
|
|
|
+ go' (x:xs) i = [f i x] ++ go' xs (i+1)
|
|
|
|
|
+
|
|
|
|
|
+ splitByChar :: Char -> String -> [String]
|
|
|
|
|
+ splitByChar c s = go' (elemIndex c s) s
|
|
|
|
|
+ where go' :: Maybe Int -> String -> [String]
|
|
|
|
|
+ go' (Nothing) s = [s]
|
|
|
|
|
+ go' (Just i) s = [b] ++ go' (elemIndex c a) a
|
|
|
|
|
+ where
|
|
|
|
|
+ (b, aRaw) = splitAt i s
|
|
|
|
|
+ a = tail aRaw
|
|
|
|
|
+
|
|
|
|
|
+ tracePPId :: Show a => [a] -> [a]
|
|
|
|
|
+ tracePPId l = if (go' l 0) then [] else l
|
|
|
|
|
+ where
|
|
|
|
|
+ go' :: Show a => [a] -> Int -> Bool
|
|
|
|
|
+ go' [] _ = False
|
|
|
|
|
+ go' (x:xs) i = trace (printf "%5d -> %s" i (show x)) (go' xs (i+1))
|