Support Misc module

Define two functions for attempting to return an element in a list that precedes
or succeeds another element.

I prefer having something like Utils.List. Perhaps I will refactor.
This commit is contained in:
William Carroll 2020-04-11 23:10:14 +01:00
parent c24c9b7fb9
commit 808e6ee484

View file

@ -0,0 +1,15 @@
module Misc exposing (..)
comesAfter : a -> List a -> Maybe a
comesAfter x xs =
case xs of
[] -> Nothing
_::[] -> Nothing
y::z::rest -> if y == x then Just z else comesAfter x (z::rest)
comesBefore : a -> List a -> Maybe a
comesBefore x xs =
case xs of
[] -> Nothing
_::[] -> Nothing
y::z::rest -> if z == x then Just y else comesAfter x (z::rest)