Skip to content

Instantly share code, notes, and snippets.

@jordanlewis
Created January 28, 2012 04:07
Show Gist options
  • Save jordanlewis/1692539 to your computer and use it in GitHub Desktop.
Save jordanlewis/1692539 to your computer and use it in GitHub Desktop.
PFDS list update
def update[A](xs: List[A], i: Int, y: A) : List[A] = (xs, i) match {
case (Nil, _) => throw new AssertionError("Invalid subscript")
case (x::xs, 0) => y::xs
case (x::xs, i) => x::update(xs, i - 1, y)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment