Add unsnoc function.
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
* Hides all Show class functions. Only the Class itself is exported. Forbids
|
||||
* custom instances that are not GHC derived.
|
||||
* Export`` encodeUtf8`` and ``decodeUtf8`` functions by default.
|
||||
* Adds ``unsnoc`` function.
|
||||
|
||||
0.1.5
|
||||
=====
|
||||
|
||||
@@ -12,6 +12,7 @@ module Protolude (
|
||||
map,
|
||||
(&),
|
||||
uncons,
|
||||
unsnoc,
|
||||
applyN,
|
||||
print,
|
||||
show,
|
||||
@@ -362,6 +363,13 @@ uncons :: [a] -> Maybe (a, [a])
|
||||
uncons [] = Nothing
|
||||
uncons (x:xs) = Just (x, xs)
|
||||
|
||||
unsnoc :: [x] -> Maybe ([x],x)
|
||||
unsnoc = foldr go Nothing
|
||||
where
|
||||
go x mxs = Just (case mxs of
|
||||
Nothing -> ([], x)
|
||||
Just (xs, e) -> (x:xs, e))
|
||||
|
||||
applyN :: Int -> (a -> a) -> a -> a
|
||||
applyN n f = X.foldr (.) identity (X.replicate n f)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user