2016-05-13 02:26:52 +00:00
|
|
|
module Sublist exposing (..)
|
2016-03-17 01:38:51 +00:00
|
|
|
|
2015-10-12 16:46:15 +00:00
|
|
|
|
2016-04-12 20:54:11 +00:00
|
|
|
version : Int
|
|
|
|
version =
|
2016-06-19 21:46:13 +00:00
|
|
|
2
|
2016-04-12 20:54:11 +00:00
|
|
|
|
|
|
|
|
2016-04-10 03:15:51 +00:00
|
|
|
type ListComparison
|
2016-06-19 21:46:13 +00:00
|
|
|
= Equal
|
|
|
|
| Superlist
|
|
|
|
| Sublist
|
|
|
|
| Unequal
|
2016-03-17 01:38:51 +00:00
|
|
|
|
2016-04-10 03:15:51 +00:00
|
|
|
|
|
|
|
sublist : List a -> List a -> ListComparison
|
2015-10-12 16:46:15 +00:00
|
|
|
sublist alist blist =
|
2016-06-19 21:46:13 +00:00
|
|
|
if alist == blist then
|
|
|
|
Equal
|
|
|
|
else if inList alist blist then
|
|
|
|
Superlist
|
|
|
|
else if inList blist alist then
|
|
|
|
Sublist
|
|
|
|
else
|
|
|
|
Unequal
|
2016-03-17 01:38:51 +00:00
|
|
|
|
2015-10-12 16:46:15 +00:00
|
|
|
|
|
|
|
inList : List a -> List a -> Bool
|
|
|
|
inList alist blist =
|
2016-06-19 21:46:13 +00:00
|
|
|
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
|