Skip to content

Commit

Permalink
adds safe tail and init to prelude. Closes #618
Browse files Browse the repository at this point in the history
  • Loading branch information
fegu committed Dec 26, 2020
1 parent febcc25 commit ee9c087
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion IHP/Prelude.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ module IHP.Prelude
, headMay
, last
, lastMay
, tail
, tailMay
, init
, initMay
, show
, module Data.String.Conversions
, module Data.Time.Clock
Expand Down Expand Up @@ -46,7 +50,7 @@ import qualified Prelude
import qualified Data.Text as Text
import Data.Proxy (Proxy (Proxy))
import Control.Monad (when, unless, mapM, mapM_, forM, forM_, sequence, sequence_, join, forever)
import Data.List hiding (head, last, unwords, unlines, words, lines, isPrefixOf, isSuffixOf, isInfixOf, intercalate, intersperse, (++), splitAt, null)
import Data.List hiding (head, last, unwords, unlines, words, lines, isPrefixOf, isSuffixOf, isInfixOf, intercalate, intersperse, (++), splitAt, null, tail, init)
import qualified Data.List as List
import Data.String.Conversions (ConvertibleStrings (convertString), cs)
import Data.Time.Clock
Expand Down Expand Up @@ -90,4 +94,18 @@ last list = Just (List.last list)
lastMay :: [a] -> Maybe a
lastMay = last

tail :: [a] -> Maybe [a]
tail [] = Nothing
tail list = Just (List.tail list)

tailMay :: [a] -> Maybe [a]
tailMay = tail

init :: [a] -> Maybe [a]
init [] = Nothing
init list = Just (List.init list)

initMay :: [a] -> Maybe [a]
initMay = init

plain = Data.String.Interpolate.i

0 comments on commit ee9c087

Please sign in to comment.