Anonymous user
Singly-linked list/Traversal: Difference between revisions
→{{header|Scala}}
m (+Stata) |
|||
Line 1,235:
=={{header|Scala}}==
You can use pattern matching for traversing a list.
<lang scala>def traverse1[T](xs: Seq[T]): Unit = xs match {▼
}▼
}</lang>▼
<lang scala>
/*
Here is a basic list definition
sealed trait List[+A]
case class Cons[+A](head: A, tail: List[A]) extends List[A]
case object Nil extends List[Nothing]
*/
case Nil => print("End")
case Cons(h, t) => {
print(h + " ")
traverse(t)
▲ }
}
=={{header|Scheme}}==
|