about summary refs log tree commit diff
path: root/website/sandbox/chord-drill-sergeant/src/Misc.elm
diff options
context:
space:
mode:
authorWilliam Carroll <wpcarro@gmail.com>2020-04-11T22·10+0100
committerWilliam Carroll <wpcarro@gmail.com>2020-04-11T22·10+0100
commit808e6ee4847a92cb763f8776149e97575d9c1961 (patch)
treeccfef45c0c7bca260963bc44d8d1594213c801ed /website/sandbox/chord-drill-sergeant/src/Misc.elm
parentc24c9b7fb940793ef75fa61d00abb31c3d56f94b (diff)
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.
Diffstat (limited to 'website/sandbox/chord-drill-sergeant/src/Misc.elm')
-rw-r--r--website/sandbox/chord-drill-sergeant/src/Misc.elm15
1 files changed, 15 insertions, 0 deletions
diff --git a/website/sandbox/chord-drill-sergeant/src/Misc.elm b/website/sandbox/chord-drill-sergeant/src/Misc.elm
new file mode 100644
index 000000000000..479234ff1546
--- /dev/null
+++ b/website/sandbox/chord-drill-sergeant/src/Misc.elm
@@ -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)