Skip to content

Instantly share code, notes, and snippets.

@stevenchanin
stevenchanin / Benchmarking Data & Functional Implementations of List
Created September 20, 2010 19:35
Benchmarking Data & Functional Implementations of List
#This is the code underneath the blog post:
#http://stevechanin.blogspot.com/2010/09/benchmarking-functional-vs-data-based.html
List = Struct.new(:head, :tail)
Cons = ->(h,t) { List.new(h,t) }
Car = ->(list) { list.head }
Cdr = ->(list) { list.tail }
#[1, [2, 3], 4, 5]
lst = Cons.(1, Cons.(Cons.(2, Cons.(3, nil)), Cons.(4, Cons.(5,nil))))