Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save deanwampler/1095c0280f956cd65e6164d334ad16b8 to your computer and use it in GitHub Desktop.
Save deanwampler/1095c0280f956cd65e6164d334ad16b8 to your computer and use it in GitHub Desktop.
scala> case class IntLinkedList(head: Int, tail: Option[IntLinkedList]) extends LinkedList:
| type Item = Int
// defined case class IntLinkedList
scala> val ill = IntLinkedList(0,
| Some(IntLinkedList(1, Some(IntLinkedList(2, None)))))
val ill: IntLinkedList = IntLinkedList(0,Some(IntLinkedList(1,Some(IntLinkedList(2,None)))))
scala> head(ill)
| tail(ill)
| head(tail(ill).get)
| head(tail(tail(ill).get).get)
val res0: ill.Item = 0
val res1: Option[LinkedList] = Some(IntLinkedList(1,Some(IntLinkedList(2,None))))
val res2: LinkedList#Item = 1
val res3: LinkedList#Item = 2
scala> h(ill)
| t(ill)
| h(t(ill).get)
| h(t(t(ill).get).get)
val res4: ill.Item = 0
val res5: Option[LinkedList] = Some(IntLinkedList(1,Some(IntLinkedList(2,None))))
val res6: LinkedList#Item = 1
val res7: LinkedList#Item = 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment