Skip to content

Instantly share code, notes, and snippets.

@ChrisBuchholz
Created July 21, 2013 10:28
Show Gist options
  • Save ChrisBuchholz/6048179 to your computer and use it in GitHub Desktop.
Save ChrisBuchholz/6048179 to your computer and use it in GitHub Desktop.
safeInit
safeInit :: [a] -> [a]
safeInit (x:xs)
| null xs = []
| otherwise = x : safeInit xs
@ChrisBuchholz
Copy link
Author

Actual safe version:

safeInit :: [a] -> Maybe [a] 
safeInit [] = Nothing
safeInit (x:[]) = Just []
safeInit (x:xs) = Just $ init (x:xs)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment