Created
March 6, 2021 21:58
-
-
Save deanwampler/1095c0280f956cd65e6164d334ad16b8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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