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