Documentation
¶
Overview ¶
Package ply is a pseudo-package that documents the builtin functions and methods added by the Ply compiler.
All the function and method names in this package are lowercased when written in Ply syntax.
Ply methods do not yield method values. That is, this expression is illegal:
intFilter := ([]int).filter
The provided examples are written in Ply, not Go, so they will not run.
Index ¶
- func Merge(recv map[T]U, rest ...map[T]U) map[T]U
- type MapTU
- type SliceT
- func (s SliceT) All(pred func(T) bool) bool
- func (s SliceT) Any(pred func(T) bool) bool
- func (s SliceT) Contains(e T) bool
- func (s SliceT) Drop(n int) SliceT
- func (s SliceT) DropWhile(pred func(T) bool) SliceT
- func (s SliceT) Filter(pred func(T) bool) SliceT
- func (s SliceT) Fold(fn func(U, T) U, acc U) U
- func (s SliceT) Foreach(fn func(T))
- func (s SliceT) Morph(fn func(T) U) []U
- func (s SliceT) Reverse() SliceT
- func (s SliceT) Sort(less func(T, T) bool) SliceT
- func (s SliceT) Take(n int) SliceT
- func (s SliceT) TakeWhile(pred func(T) bool) SliceT
- func (s SliceT) Tee(fn func(T)) SliceT
- func (s SliceT) ToMap(fn func(T) U) map[T]U
- func (s SliceT) ToSet() map[T]struct{}
- func (s SliceT) Uniq() SliceT
- type T
- type U
- type V
- type W
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Merge ¶
Merge copies the contents of each map in rest into recv and returns it. If recv is nil, a new map will be allocated to hold the contents. Thus it is idiomatic to write:
m3 := merge(nil, m1, m2)
to avoid modifying m1 or m2. Conversely, if it is acceptable to reuse m1's memory, write:
m1 = merge(m1, m2)
Like append, merge is only valid as an expression, not a statement. In other words, you *must* make use of its return value.
Types ¶
type MapTU ¶
type MapTU int
MapTU is a map with element type T and key type U. This includes named types whose underlying type is map[T]U.
func (MapTU) Contains ¶
Contains returns true if m contains e. It is shorthand for:
_, ok := m[e] return ok
func (MapTU) Filter ¶
Filter returns a new map containing only the key/value pairs of m that satisfy pred.
type SliceT ¶
type SliceT int
SliceT is a slice with element type T. This includes named types whose underlying type is []T.
func (SliceT) All ¶
All returns true if all elements of s satisfy pred. It returns as soon as it encounters an element that does not satisfy pred.
func (SliceT) Any ¶
Any returns true if any elements of s satisfy pred. It returns as soon as it encounters an element that satisfies pred.
func (SliceT) Contains ¶
Contains returns true if s contains e. T must be a comparable type; see https://golang.org/ref/spec#Comparison_operators
As a special case, T may be a slice, map, or function if e is nil.
func (SliceT) Drop ¶
Drop returns a slice omitting the first n elements of s. The returned slice shares the same underlying memory as s. If n is greater than len(s), the latter is used. In other words, Drop is short for:
s2 := s[min(n, len(s)):]
Note that is s is nil, the returned slice will also be nil, whereas if s is merely empty (but non-nil), the returned slice will also be non-nil.
func (SliceT) DropWhile ¶
DropWhile returns a new slice omitting the initial elements of s that satisfy pred. That is, unlike Filter, the slice returned by DropWhile is guaranteed to be a contiguous subset of s beginning at the first element that does not satisfy pred.
func (SliceT) Filter ¶
Filter returns a new slice containing only the elements of s that satisfy pred.
func (SliceT) Fold ¶
Fold returns the result of repeatedly applying fn to an initial "accumulator" value and each element of s. If no initial value is provided, Fold uses the first element of s. Note that this implies that T and U are the same type, and that s is not empty. If s is empty and no initial value is provided, Fold panics.
Fold is implemented as a "left fold," which may affect the result if fn is not associative. Given the example below:
xs := []int{1, 2, 3, 4} sub := func(x, y int) int { return x - y } xs.fold(sub)
Fold yields ((1 - 2) - 3) - 4 == -8, whereas a "right fold" would instead yield 1 - (2 - (3 - 4)) == -2.
func (SliceT) Morph ¶
Morph returns a new slice containing the result of applying fn to each element of s.
func (SliceT) Sort ¶
Sort returns a new slice containing the elements of s in sorted order, according to the less function. If less is not supplied, s must either be an ordered type or implement sort.Interface. In the former case, the < operator is used as the less function. See https://golang.org/ref/spec#Comparison_operators
func (SliceT) Take ¶
Take returns a slice containing the first n elements of s. The returned slice shares the same underlying memory as s. If n is greater than len(s), the latter is used. In other words, Take is short for:
s2 := s[:min(n, len(s))]
Note that is s is nil, the returned slice will also be nil, whereas if s is merely empty (but non-nil), the returned slice will also be non-nil.
func (SliceT) TakeWhile ¶
TakeWhile returns a new slice containing the initial elements of s that satisfy pred. That is, unlike Filter, the slice returned by TakeWhile is guaranteed to be a contiguous subset of s beginning at the first element.
func (SliceT) ToMap ¶
ToMap returns a map in which each element of s is mapped to a corresponding value as computed by fn. Note that if s contains duplicate elements, earlier elements will be overwritten in the map. fn is called on every element, regardless of the number of duplicates.
type T ¶
type T int
T is a generic type.
func Enum ¶
Enum enumerates the range [x,y) using step s, which may be negative. T must be an integer type, which includes byte and rune. Only one argument is mandatory:
- enum(x, y) is equivalent to enum(x, y, 1) - enum(y) is equivalent to enum(0, y, 1)
Enum returns an empty slice (not nil) if x == y. Enum panics if y is unreachable, i.e. if s == 0 || (x > y && s > 0) || (x < y && s < 0).
func Max ¶
Max returns the larger of x or y, as determined by the > operator. T must be an ordered type; see https://golang.org/ref/spec#Comparison_operators
If x and y are constants, then the result of Max is also a constant.
func Min ¶
Min returns the smaller of x or y, as determined by the > operator. T must be an ordered type; see https://golang.org/ref/spec#Comparison_operators
If x and y are constants, then the result of Min is also a constant.
type V ¶
type V int
V is a generic type.