LinkedList

type LinkedListElement<T> = { value : T; var next : ?LinkedListElement<T> }

type LinkedList<T> = ?{ var head : LinkedListElement<T>; var tail : LinkedListElement<T> }

public func empty<T>() : LinkedList<T>

Create an empty LinkedList

public func prepend<T>(x : T, l : LinkedList<T>) : LinkedList<T>

Prepend an element to a LinkedList, mutating the underlying LinkedList. Returns the new LinkedList

public func append<T>(l : LinkedList<T>, x : T) : LinkedList<T>

Append an element to a LinkedList, mutating the underlying LinkedList. Returns the new LinkedList

public func merge<T>(l1 : LinkedList<T>, l2 : LinkedList<T>) : LinkedList<T>

Merge two LinkedLists, mutating the underlying LinkedList arguments passed in. Returns the merged LinkedLists

public func equal<T>(
  l1 : LinkedList<T>,
  l2 : LinkedList<T>,
  equal : (T, T) -> Bool
) : Bool

Takes in two LinkedLists and a user defined equivalence function for each element of the LinkedList. Returns a boolean

public func toText<T>(ll : LinkedList<T>, toText : T -> Text) : Text

For Debugging: Takes in a LinkedList and toText function, and returns a textual representation of the LinkedList