apelsin-1.0: src/List2.hs
module List2 (stripw, intmean) where
import Prelude hiding (foldr, foldl, foldr1, foldl1)
import Data.Char
import Data.Foldable
stripw :: String -> String
stripw = dropWhileRev isSpace . dropWhile isSpace
dropWhileRev :: (a -> Bool) -> [a] -> [a]
dropWhileRev p = foldr (\x xs -> if p x && null xs then [] else x:xs) []
intmean :: (Integral i, Foldable f) => f i -> i
intmean l = if len == 0 then 0 else lsum `div` len where
(len, lsum) = foldl' (\(!n, !s) elm -> (n+1, s+elm)) (0, 0) l