tpl: Improve template funcs GoDoc

This commit is contained in:
Bjørn Erik Pedersen
2022-12-21 13:11:08 +01:00
parent aa2c724195
commit cd1ed563a8
17 changed files with 170 additions and 163 deletions

View File

@@ -19,19 +19,21 @@ import (
"reflect"
)
// Complement gives the elements in the last element of seqs that are not in
// Complement gives the elements in the last element of ls that are not in
// any of the others.
// All elements of seqs must be slices or arrays of comparable types.
//
// All elements of ls must be slices or arrays of comparable types.
//
// The reasoning behind this rather clumsy API is so we can do this in the templates:
// {{ $c := .Pages | complement $last4 }}
func (ns *Namespace) Complement(seqs ...any) (any, error) {
if len(seqs) < 2 {
//
// {{ $c := .Pages | complement $last4 }}
func (ns *Namespace) Complement(ls ...any) (any, error) {
if len(ls) < 2 {
return nil, errors.New("complement needs at least two arguments")
}
universe := seqs[len(seqs)-1]
as := seqs[:len(seqs)-1]
universe := ls[len(ls)-1]
as := ls[:len(ls)-1]
aset, err := collectIdentities(as...)
if err != nil {