githubEdit

Slice

The slice type handles arrays of any other type with extensive membership, set, and aggregation operations.

Overview

Property
Value

Go Type

[]T for any supported type T

Database Schema

array<T> / option<array<T>>

CBOR Encoding

Direct

Sortable

No (use element access for sorting)

Definition

type Post struct {
    som.Node

    Title    string
    Tags     []string        // String slice
    Scores   []int           // Integer slice
    Ratings  []float64       // Float slice
    Authors  []*User         // Node slice
    Metadata []CustomStruct  // Struct slice
}

Byte Slices

Byte slices have special handling:

Schema

Generated SurrealDB schema:

Filter Operations

Empty/Nil Checks

Single Element Membership

Multiple Element Membership

Equality Checks

Set Membership (Is-In)

Element Access

Length Operations

Array Transformations

Set Operations

Search Operations

Aggregation Operations

Boolean Array Operations

For boolean arrays:

Logical Array Operations

Pattern Matching

Sorting

Slices themselves are not directly sortable. Use element access:

Method Chaining

Slice filters support powerful chaining:

Common Patterns

Has Any Tags

Filter by Tag

Multiple Required Tags

Score Range

Unique Tags Only

Complete Example

Filter Reference Table

Operation
Description
Returns

IsEmpty()

Check if empty

Bool filter

NotEmpty()

Check if not empty

Bool filter

Empty(bool)

Explicit empty check

Bool filter

Contains(val)

Contains element

Bool filter

ContainsNot(val)

Doesn't contain

Bool filter

ContainsAll(vals...)

Contains all

Bool filter

ContainsAny(vals...)

Contains any

Bool filter

ContainsNone(vals...)

Contains none

Bool filter

AnyEqual(val)

Any equals

Bool filter

AllEqual(val)

All equal

Bool filter

AnyFuzzyMatch(pattern)

Any matches pattern

Bool filter

AllFuzzyMatch(pattern)

All match pattern

Bool filter

AnyIn(vals...)

Any in set

Bool filter

AllIn(vals...)

All in set

Bool filter

NoneIn(vals...)

None in set

Bool filter

First()

First element

Element filter

Last()

Last element

Element filter

At(index)

Element at index

Element filter

Len()

Array length

Numeric filter

Distinct()

Unique elements

Slice filter

Reverse()

Reversed array

Slice filter

SortAsc()

Sorted ascending

Slice filter

SortDesc()

Sorted descending

Slice filter

Slice(start, len)

Subsequence

Slice filter

Concat(arr)

Concatenate

Slice filter

Intersect(arr)

Intersection

Slice filter

Union(arr)

Union

Slice filter

Complement(arr)

Complement

Slice filter

Diff(arr)

Difference

Slice filter

FindIndex(val)

Find index

Numeric filter

FilterIndex(val)

Filter indices

Slice filter

All()

All truthy

Bool filter

Any()

Any truthy

Bool filter

Min()

Minimum value

Numeric filter

Max()

Maximum value

Numeric filter

Join(sep)

Join to string

String filter

Matches(pattern)

Pattern match

Slice filter

Last updated