-- | misc helper functions

module Math.FreeModule.Helper where

--------------------------------------------------------------------------------

import Data.Ord
import Data.List

--------------------------------------------------------------------------------

(<#>) :: (a -> b) -> (c -> d) -> (a,c) -> (b,d)
(f<#>g) (x,y) = (f x, g y)
 
equating :: Eq b => (a -> b) -> a -> a -> Bool
equating f x y = (f x == f y)
 
sortByFst :: Ord b => [(b,c)] -> [(b,c)]
sortByFst = sortBy (comparing fst)

filterNotZero :: (Eq c, Num c) => [(b,c)] -> [(b,c)]
filterNotZero = filter (\(b,c) -> (c/=0))

--------------------------------------------------------------------------------