Skip to content

Commit

Permalink
Make prev and next faster (#74)
Browse files Browse the repository at this point in the history
  • Loading branch information
jfmengels committed Dec 17, 2021
1 parent 9c1276b commit a4562d6
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/Maybe/Extra.elm
Original file line number Diff line number Diff line change
Expand Up @@ -698,8 +698,13 @@ Advanced functional programmers will recognize this as the implementation of `*>
-}
next : Maybe a -> Maybe b -> Maybe b
next =
map2 (\b a -> always a b)
next a b =
case a of
Nothing ->
Nothing

Just _ ->
b


{-| Take two `Maybe` values. If the second one equals `Nothing`, return `Nothing`. Otherwise return the first value.
Expand All @@ -717,5 +722,10 @@ Advanced functional programmers will recognize this as the implementation of `<*
-}
prev : Maybe a -> Maybe b -> Maybe a
prev =
map2 always
prev a b =
case b of
Nothing ->
Nothing

Just _ ->
a

0 comments on commit a4562d6

Please sign in to comment.