git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
nub, nubBy, elem, notElem
52ebe69Phil Freeman
prelude/prelude.purs+15
@@ -644,6 +644,21 @@ module Data.Array where
644 take _ [] = []
644 take _ [] = []
645 take n (x:xs) = x : take (n - 1) xs
645 take n (x:xs) = x : take (n - 1) xs
646
646
647+ nub :: forall a. (Eq a) => [a] -> [a]
648+ nub = nubBy (==)
649+
650+ nubBy :: forall a. (a -> a -> Boolean) -> [a] -> [a]
651+ nubBy _ [] = []
652+ nubBy (==) (x:xs) = x : nubBy (==) (filter (\y -> not (x == y)) xs)
653+
654+ elem :: forall a. (Eq a) => a -> [a] -> Boolean
655+ elem a (a' : as) | a == a' = true
656+ elem a (_ : as) = a `elem` as
657+ elem _ _ = false
658+
659+ notElem :: forall a. (Eq a) => a -> [a] -> Boolean
660+ notElem a as = not (a `elem` as)
661+
647 instance showArray :: (Show a) => Show [a] where
662 instance showArray :: (Show a) => Show [a] where
648 show xs = "[" ++ joinWith (map show xs) "," ++ "]"
663 show xs = "[" ++ joinWith (map show xs) "," ++ "]"
649
664