2020-04-12 00:10:14 +02:00
|
|
|
module Misc exposing (..)
|
|
|
|
|
2020-04-13 16:07:03 +02:00
|
|
|
import Array exposing (Array)
|
|
|
|
|
2020-04-12 17:43:34 +02:00
|
|
|
|
2020-04-12 00:10:14 +02:00
|
|
|
comesAfter : a -> List a -> Maybe a
|
|
|
|
comesAfter x xs =
|
|
|
|
case xs of
|
2020-04-12 17:43:34 +02:00
|
|
|
[] ->
|
|
|
|
Nothing
|
|
|
|
|
|
|
|
_ :: [] ->
|
|
|
|
Nothing
|
|
|
|
|
|
|
|
y :: z :: rest ->
|
|
|
|
if y == x then
|
|
|
|
Just z
|
|
|
|
|
|
|
|
else
|
|
|
|
comesAfter x (z :: rest)
|
|
|
|
|
2020-04-12 00:10:14 +02:00
|
|
|
|
|
|
|
comesBefore : a -> List a -> Maybe a
|
|
|
|
comesBefore x xs =
|
|
|
|
case xs of
|
2020-04-12 17:43:34 +02:00
|
|
|
[] ->
|
|
|
|
Nothing
|
|
|
|
|
|
|
|
_ :: [] ->
|
|
|
|
Nothing
|
|
|
|
|
|
|
|
y :: z :: rest ->
|
|
|
|
if z == x then
|
|
|
|
Just y
|
|
|
|
|
|
|
|
else
|
|
|
|
comesBefore x (z :: rest)
|
2020-04-13 16:07:03 +02:00
|
|
|
|
|
|
|
|
|
|
|
find : (a -> Bool) -> List a -> Maybe a
|
|
|
|
find pred xs =
|
|
|
|
case xs |> List.filter pred of
|
|
|
|
[] ->
|
|
|
|
Nothing
|
|
|
|
|
|
|
|
x :: _ ->
|
|
|
|
Just x
|