sexp

package module
v0.0.0-...-30b32f1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 19, 2022 License: JSON Imports: 3 Imported by: 0

README

An S-Expression library written in Go.

S-Expressions can be modelled using a variety of structures. This package provides three implementations:

Slice uses an []interface{} as its backing store but is accessed via list semantics. As such it is suited to tasks
where breadth-first search and speed of element access are priorities;

All three S-Expression data structures store interface{} objects and as such can be used to store each other in
arbitrary numbers and to arbitrary depths.

An additional SliceValue type is provides which uses a reflect.Value containing a slice as its backing store. This
is not guaranteed to be usable as an S-Expression but provides a convenient way to reuse many of the functions
specified for S-Expressions on slices of any type.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Append

func Append(container, value interface{})

func BlockClear

func BlockClear(container interface{}, d, n int)

func BlockCopy

func BlockCopy(container interface{}, d, s, n int)

func BlockSwap

func BlockSwap(container interface{}, d, s, n int)

func Cap

func Cap(container interface{}) (l int)

func Collect

func Collect(container interface{}, f interface{}) (r interface{}, ok bool)

func Combine

func Combine(left, right interface{}, f func(interface{}, interface{}) interface{}) (r interface{})

Combine takes two parameters and applies a function to them. In the case of scalar parameters the function is applied once and the result returned. In the case of vector parameters the function is applied to each matched pair of elements and the result returned. A vector result will always have the same type as the left-hand parameter and the number of elements in the result vector will be the same as the number of elements in the lef-hand parameter with trailing unmatched values combined with the correct zero value for the contained type.

func Count

func Count(container interface{}, f func(interface{}) bool) (n int)

func Cycle

func Cycle(container interface{}, count int, f func(interface{})) (i int, ok bool)

func Dense

func Dense(container interface{}, d, t float64, f func(interface{}) bool) bool

func Density

func Density(container interface{}, f func(interface{}) bool) (r float64)

func Depth

func Depth(container interface{}) (d int)

Calculate the depth of nesting of a container. A scalar value and an empty container will both return a depth of zero. All other containers will return a depth of 1+.

func Each

func Each(container, f interface{}) (ok bool)

func Equal

func Equal(x, y interface{}) bool

func Feed

func Feed(container interface{}, c chan interface{}, f func(x interface{}) interface{})

func First

func First(container interface{}, i int) interface{}

func Flatten

func Flatten(container interface{})

func Last

func Last(container interface{}, i int) interface{}

func Len

func Len(container interface{}) (l int)

func Most

func Most(container interface{}, t float64, f func(interface{}) bool) bool

func One

func One(container interface{}, f func(interface{}) bool) (b bool)
While processes values from a container whilst a condition is true or until the end of the container is reached.
Returns the count of items which pass the test.
func While(container interface{}, f func(interface{}) bool) (i int) {
	jittery.Catch(func() {
		Each(container, func(x interface{}) {
			if f(x) {
				i++
			} else {
				jittery.Throw()
			}
		})
	})
	return
}

// Until processes values from a container until a condition is true or until the end of the container is reached. // Returns the count of items which fail the test.

func Until(container interface{}, f func(interface{}) bool) (i int) {
	jittery.Catch(func() {
		Each(container, func(x interface{}) {
			if f(x) {
				jittery.Throw()
			} else {
				i++
			}
		})
	})
	return
}
func Any(container interface{}, f func(interface{}) bool) (b bool) {
	if l := Until(container, f); l > 0 {
		 b = l < Len(container)
	}
	return
}
func All(container interface{}, f func(interface{}) bool) (b bool) {
	if l := While(container, f); l > 0 {
		b = l == Len(container)
	}
	return
}
func None(container interface{}, f func(interface{}) bool) (b bool) {
	return Until(container, f) == Len(container)
}

func Overwrite

func Overwrite(destination interface{}, offset int, source interface{})

func Pipe

func Pipe(container interface{}, f func(x interface{}) interface{}) (c chan interface{})

func Reallocate

func Reallocate(container interface{}, length, capacity int) (r interface{})

Create a new memory container and copy contents across to it. Returns nil when reallocation fails.

func Reduce

func Reduce(container, seed interface{}, f interface{}) (r interface{}, ok bool)

func Repeat

func Repeat(container interface{}, count int)

func Resize

func Resize(container interface{}, x, n int) (r interface{})

Resize a container by a delta of n elements at the insertion point x. Returns nil when expansion fails.

func Reverse

func Reverse(container interface{})

func Subslice

func Subslice(container interface{}, start, end int) (r interface{})

func Transform

func Transform(container, t interface{}) (ok bool)

func Until

func Until(container, f interface{}) (count int)

func WaitFor

func WaitFor(f func())

func While

func While(container, f interface{}) (count int)

Types

type Appendable

type Appendable interface {
	Append(interface{})
}

type Blitter

type Blitter interface {
	BlockCopy(destination, source, count int)
	BlockClear(start, count int)
}

type Collectable

type Collectable interface {
	Collect(f interface{}) (r interface{}, ok bool)
}

type Combinable

type Combinable interface {
	Combine(interface{}, func(interface{}, interface{}) interface{}) interface{}
}

type Deque

type Deque interface {
	PopFirst() interface{}
	PopLast() interface{}
	Append(i interface{})
	Prepend(i interface{})
}

type Equatable

type Equatable interface {
	Equal(interface{}) bool
}

type Feeder

type Feeder interface {
	Feed(chan interface{}, func(interface{}) interface{})
}

type FixedSize

type FixedSize interface {
	Linear
	Cap() int
}

type Flattenable

type Flattenable interface {
	Flatten()
}

type Indexable

type Indexable interface {
	IndexedReader
	IndexedWriter
}

type IndexedReader

type IndexedReader interface {
	Linear
	At(index int) interface{}
}

type IndexedWriter

type IndexedWriter interface {
	Set(index int, value interface{})
	Clear(index int)
}

type Iterable

type Iterable interface {
	Each(function interface{}) bool
}

type Linear

type Linear interface {
	Len() int
}

type Linkable

type Linkable interface {
	Linear
	Start() chain.Node
	End() chain.Node
}

type Mappable

type Mappable interface {
	Linear
	MappedReader
	MappedWriter
}

type MappedReader

type MappedReader interface {
	At(key interface{}) interface{}
	Keys() []interface{}
}

type MappedWriter

type MappedWriter interface {
	Set(key interface{}, value interface{})
	Clear(key interface{})
}

type Nested

type Nested interface {
	Depth() int
}

type Overwriteable

type Overwriteable interface {
	Overwrite(offset interface{}, container interface{})
}

type PartiallyIterable

type PartiallyIterable interface {
	While(condition bool, function interface{}) (count int)
}

type Piper

type Piper interface {
	Pipe(func(interface{}) interface{}) chan interface{}
}

type Reducible

type Reducible interface {
	Reduce(seed, function interface{}) (r interface{}, ok bool)
}

type Repeatable

type Repeatable interface {
	Repeat(count int)
}

type Resizeable

type Resizeable interface {
	FixedSize
	At(index int) interface{}
	Set(index int, value interface{})
	Reallocate(l, c int)
}

type Reversible

type Reversible interface {
	Reverse()
}

type Sliceable

type Sliceable interface {
	Subslice(start, end int) interface{}
}

type Transformable

type Transformable interface {
	Transform(interface{}) bool
}

type Typed

type Typed interface {
	Type() reflect.Type
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL