github.com/markusbkk/elvish@v0.0.0-20231204143114-91dc52438621/pkg/persistent/list/list.go (about) 1 // Package list implements persistent list. 2 package list 3 4 // List is a persistent list. 5 type List interface { 6 // Len returns the number of values in the list. 7 Len() int 8 // Conj returns a new list with an additional value in the front. 9 Conj(interface{}) List 10 // First returns the first value in the list. 11 First() interface{} 12 // Rest returns the list after the first value. 13 Rest() List 14 } 15 16 // Empty is an empty list. 17 var Empty List = &list{} 18 19 type list struct { 20 first interface{} 21 rest *list 22 count int 23 } 24 25 func (l *list) Len() int { 26 return l.count 27 } 28 29 func (l *list) Conj(val interface{}) List { 30 return &list{val, l, l.count + 1} 31 } 32 33 func (l *list) First() interface{} { 34 return l.first 35 } 36 37 func (l *list) Rest() List { 38 return l.rest 39 }