src/main/scala/sublist.scala

1
2
3
4
5
6
7
8
9
10
11
12
object Sublist extends Enumeration {
  val Equal, Sublist, Superlist, Unequal = Value
}

class Sublist {
  def sublist[A](list1: List[A], list2: List[A]) = {
    if (list1 == list2)                 Sublist.Equal
    else if (list1 containsSlice list2) Sublist.Superlist
    else if (list2 containsSlice list1) Sublist.Sublist
    else                                Sublist.Unequal
  }
}

Comments

Discovered containsSlice so was able to simplify :)

helenst commented 11 May 2016 at 15:36 UTC

well, I thought that just using containsSlice would be too trivial, so I implemented my own version of it. :-)

abo64 commented 12 May 2016 at 05:21 UTC

I guess it's good I didn't discover it straight away, but nice to know it's there!

helenst commented 12 May 2016 at 07:41 UTC

You're not logged in right now. Please login via GitHub to comment