Plan 9 from Bell Labs’s /usr/web/sources/contrib/fernan/nhc98/src/prelude/List/Partition.hs

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


module List where

-- partition takes a predicate and a list and returns a pair of lists:
-- those elements of the argument list that do and do not satisfy the
-- predicate, respectively; i,e,,
--
-- partition p xs == (filter p xs, filter (not . p) xs).

partition               :: (a -> Bool) -> [a] -> ([a],[a])
partition p xs          =  foldr select ([],[]) xs
                           where select x ~(ts,fs) | p x       = (x:ts,fs)
                                                   | otherwise = (ts, x:fs)

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.