mirror of
https://github.com/correl/elm.git
synced 2024-12-22 11:09:08 +00:00
39 lines
677 B
Text
39 lines
677 B
Text
module Sublist (..) where
|
|
|
|
|
|
version : Int
|
|
version =
|
|
2
|
|
|
|
|
|
type ListComparison
|
|
= Equal
|
|
| Superlist
|
|
| Sublist
|
|
| Unequal
|
|
|
|
|
|
sublist : List a -> List a -> ListComparison
|
|
sublist alist blist =
|
|
if alist == blist then
|
|
Equal
|
|
else if inList alist blist then
|
|
Superlist
|
|
else if inList blist alist then
|
|
Sublist
|
|
else
|
|
Unequal
|
|
|
|
|
|
inList : List a -> List a -> Bool
|
|
inList alist blist =
|
|
let
|
|
getLastInList sublist =
|
|
Maybe.withDefault [] (List.tail sublist)
|
|
in
|
|
if (List.length alist) < (List.length blist) then
|
|
False
|
|
else if (List.take (List.length blist) alist) == blist then
|
|
True
|
|
else
|
|
inList (getLastInList alist) blist
|