File: list.go

package info (click to toggle)
elvish 0.21.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 6,372 kB
  • sloc: javascript: 236; sh: 130; python: 104; makefile: 88; xml: 9
file content (39 lines) | stat: -rw-r--r-- 703 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Package list implements persistent list.
package list

// List is a persistent list.
type List interface {
	// Len returns the number of values in the list.
	Len() int
	// Conj returns a new list with an additional value in the front.
	Conj(any) List
	// First returns the first value in the list.
	First() any
	// Rest returns the list after the first value.
	Rest() List
}

// Empty is an empty list.
var Empty List = &list{}

type list struct {
	first any
	rest  *list
	count int
}

func (l *list) Len() int {
	return l.count
}

func (l *list) Conj(val any) List {
	return &list{val, l, l.count + 1}
}

func (l *list) First() any {
	return l.first
}

func (l *list) Rest() List {
	return l.rest
}