Skip to content

Commit 6d5fb94

Browse files
authored
added solution without mapMaybe (#84)
1 parent 6cc8ea8 commit 6d5fb94

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

src/Solutions/DataTypes.idr

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,11 @@ lastMaybe (x :: Nil) = Just x
204204
lastMaybe (_ :: xs) = lastMaybe xs
205205

206206
initMaybe : List a -> Maybe (List a)
207-
initMaybe Nil = Nothing
208-
initMaybe (x :: Nil) = Just Nil
209-
initMaybe (x :: xs) = mapMaybe (x ::) (initMaybe xs)
207+
initMaybe l = case l of
208+
Nil => Nothing
209+
x :: xs => case initMaybe xs of
210+
Nothing => Just Nil
211+
Just ys => Just (x :: ys)
210212

211213
foldList : (acc -> el -> acc) -> acc -> List el -> acc
212214
foldList fun vacc Nil = vacc

0 commit comments

Comments
 (0)