Split Dodge.Base

This commit is contained in:
2022-06-19 11:34:59 +01:00
parent 6cc29813d8
commit df1f3ad6b0
15 changed files with 106 additions and 88 deletions
+15
View File
@@ -4,6 +4,9 @@ module ListHelp
, insertOver
, swapIndices
, (!?)
, safeHead
, safeUncons
, errorHead
)where
import Data.List
@@ -31,3 +34,15 @@ xs !? n
0 -> Just x
_ -> r (k-1)) (const Nothing) xs n
{-# INLINABLE (!?) #-}
safeHead :: [a] -> Maybe a
safeHead (x:_) = Just x
safeHead _ = Nothing
safeUncons :: [a] -> Maybe (a,[a])
safeUncons (x:xs) = Just (x,xs)
safeUncons _ = Nothing
errorHead :: String -> [a] -> a
errorHead _ (x:_) = x
errorHead s [] = error s