diff --git a/list/list.go b/list/list.go index b5934a5..7e4a134 100644 --- a/list/list.go +++ b/list/list.go @@ -35,17 +35,22 @@ func Empty() IList { var emptyList = Empty() -func New(val any) *List { +func New(val any) IList { this := new(List) this.Value = val this.next = emptyList return this } +func Cons(val any, rest IList) IList { + this := new(List) + this.Value = val + this.next = rest + return this +} + func (this *List) Conj(val any) IList { - new_head := New(val) - new_head.next = this - return new_head + return Cons(val, this) }