go-adaptive-functions: github.com/spatialcurrent/go-adaptive-functions/af Index | Files

package af

import "github.com/spatialcurrent/go-adaptive-functions/af"

Package af contains a set of adapative functions.

Index

Package Files

Add.go Base.go Bottom.go BoundingBox.go Clean.go Coalesce.go Concat.go Definition.go Divide.go ErrorInvalidArguments.go ErrorOverflow.go First.go Flatten.go Fold.go Format.go Function.go Functions.go GetLength.go IIn.go In.go Intersects.go JSON.go Join.go Last.go Limit.go Lookup.go Max.go Mean.go Min.go Multiply.go Now.go Pow.go Prefix.go Repeat.go Replace.go Second.go Slice.go Sort.go Split.go Stringify.go Subtract.go Suffix.go Sum.go TestCase.go TileX.go TileY.go ToArray.go ToBigEndian.go ToBytes.go ToFloat32.go ToFloat64.go ToFloat64Array.go ToInt.go ToInt16.go ToInt32.go ToInt64.go ToInt8.go ToIntArray.go ToItems.go ToKeys.go ToLittleEndian.go ToLower.go ToSet.go ToString.go ToStringArray.go ToStringSet.go ToTime.go ToTitle.go ToUpper.go ToValues.go Top.go Trim.go Types.go Within.go af.go

Variables

var Add = Function{
    Name:    "Add",
    Aliases: []string{"add"},
    Definitions: []Definition{
        Definition{Inputs: []interface{}{reflect.Int, reflect.Int}, Output: reflect.Int},
        Definition{Inputs: []interface{}{reflect.Int, reflect.Int64}, Output: reflect.Int},
        Definition{Inputs: []interface{}{reflect.Int, reflect.Float64}, Output: reflect.Float64},
        Definition{Inputs: []interface{}{reflect.Int64, reflect.Int}, Output: reflect.Int},
        Definition{Inputs: []interface{}{reflect.Int64, reflect.Int64}, Output: reflect.Int},
        Definition{Inputs: []interface{}{reflect.Int64, reflect.Float64}, Output: reflect.Float64},
        Definition{Inputs: []interface{}{reflect.Float64, reflect.Int}, Output: reflect.Int},
        Definition{Inputs: []interface{}{reflect.Float64, reflect.Int64}, Output: reflect.Int},
        Definition{Inputs: []interface{}{reflect.Float64, reflect.Float64}, Output: reflect.Float64},
        Definition{Inputs: []interface{}{reflect.String, reflect.String}, Output: reflect.String},
        Definition{Inputs: []interface{}{reflect.Int, reflect.String}, Output: reflect.String},
        Definition{Inputs: []interface{}{reflect.Int32, reflect.String}, Output: reflect.String},
        Definition{Inputs: []interface{}{reflect.Int64, reflect.String}, Output: reflect.String},
        Definition{Inputs: []interface{}{reflect.Float64, reflect.String}, Output: reflect.String},
        Definition{Inputs: []interface{}{reflect.String, reflect.Int}, Output: reflect.String},
        Definition{Inputs: []interface{}{reflect.String, reflect.Int32}, Output: reflect.String},
        Definition{Inputs: []interface{}{reflect.String, reflect.Int64}, Output: reflect.String},
        Definition{Inputs: []interface{}{reflect.String, reflect.Float64}, Output: reflect.String},
        Definition{Inputs: []interface{}{reflect.Slice, reflect.Array}, Output: reflect.Slice},
        Definition{Inputs: []interface{}{reflect.Slice, reflect.Slice}, Output: reflect.Slice},
        Definition{Inputs: []interface{}{reflect.Array, reflect.Array}, Output: reflect.Slice},
        Definition{Inputs: []interface{}{reflect.Array, reflect.Slice}, Output: reflect.Slice},
        Definition{Inputs: []interface{}{reflect.Map, reflect.Map}, Output: reflect.Map},
    },
    Function: add,
}
var Base = Function{
    Name:    "Base",
    Aliases: []string{"base"},
    Definitions: []Definition{
        Definition{Inputs: []interface{}{stringType}, Output: stringType},
    },
    Function: func(args []interface{}) (interface{}, error) {
        if str, ok := args[0].(string); ok {
            return filepath.Base(str), nil
        }
        return nil, &ErrorInvalidArguments{Function: "Base", Arguments: args}
    },
}
var Bottom = Function{
    Name:    "Bottom",
    Aliases: []string{"bottom"},
    Definitions: []Definition{
        Definition{Inputs: []interface{}{stringIntMapType, intType}, Output: stringArrayType},
        Definition{Inputs: []interface{}{stringIntMapType, intType, intType}, Output: stringArrayType},
    },
    Function: bottom,
}
var BoundingBox = Function{
    Name:    "BoundingBox",
    Aliases: []string{"boundingBox", "bbox"},
    Definitions: []Definition{
        Definition{Inputs: []interface{}{reflect.Array}, Output: float64ArrayType},
        Definition{Inputs: []interface{}{reflect.Slice}, Output: float64ArrayType},
    },
    Function: boundingBox,
}
var Clean = Function{
    Name:    "Clean",
    Aliases: []string{"clean"},
    Definitions: []Definition{
        Definition{Inputs: []interface{}{stringType}, Output: stringType},
    },
    Function: func(args []interface{}) (interface{}, error) {
        if str, ok := args[0].(string); ok {
            return filepath.Clean(str), nil
        }
        return nil, &ErrorInvalidArguments{Function: "Clean", Arguments: args}
    },
}
var Coalesce = Function{
    Name:        "Coalesce",
    Aliases:     []string{"coalesce"},
    Definitions: []Definition{},
    Function:    coalesce,
}
var Concat = Function{
    Name:    "Concat",
    Aliases: []string{"concat"},
    Definitions: []Definition{
        Definition{Inputs: []interface{}{reflect.Array}, Output: reflect.String},
        Definition{Inputs: []interface{}{reflect.Slice}, Output: reflect.String},
    },
    Function: concat,
}
var Divide = Function{
    Name:    "Divide",
    Aliases: []string{"divide"},
    Definitions: []Definition{
        Definition{Inputs: []interface{}{reflect.Int, reflect.Int}, Output: reflect.Int},
        Definition{Inputs: []interface{}{reflect.Int, reflect.Int64}, Output: reflect.Int},
        Definition{Inputs: []interface{}{reflect.Int, reflect.Float64}, Output: reflect.Float64},
        Definition{Inputs: []interface{}{reflect.Int64, reflect.Int}, Output: reflect.Int},
        Definition{Inputs: []interface{}{reflect.Int64, reflect.Int64}, Output: reflect.Int},
        Definition{Inputs: []interface{}{reflect.Int64, reflect.Float64}, Output: reflect.Float64},
        Definition{Inputs: []interface{}{reflect.Float64, reflect.Int}, Output: reflect.Int},
        Definition{Inputs: []interface{}{reflect.Float64, reflect.Int64}, Output: reflect.Int},
        Definition{Inputs: []interface{}{reflect.Float64, reflect.Float64}, Output: reflect.Float64},
    },
    Function: divide,
}
var First = Function{
    Name:    "First",
    Aliases: []string{"first"},
    Definitions: []Definition{
        Definition{Inputs: []interface{}{byteArrayType}, Output: reflect.Uint8},
        Definition{Inputs: []interface{}{uint8ArrayType}, Output: reflect.Uint8},
        Definition{Inputs: []interface{}{intArrayType}, Output: reflect.Int},
        Definition{Inputs: []interface{}{int64ArrayType}, Output: reflect.Int64},
        Definition{Inputs: []interface{}{float64ArrayType}, Output: reflect.Float64},
        Definition{Inputs: []interface{}{stringArrayType}, Output: reflect.String},
        Definition{Inputs: []interface{}{stringIntMapSliceType}, Output: stringIntMapType},
        Definition{Inputs: []interface{}{interfaceArrayType}, Output: nil},
        Definition{Inputs: []interface{}{reflect.String}, Output: reflect.Uint8},
        Definition{Inputs: []interface{}{reflect.Map}, Output: nil},
    },
    Function: first,
}
var Flatten = Function{
    Name:    "Flatten",
    Aliases: []string{"flatten"},
    Definitions: []Definition{
        Definition{Inputs: []interface{}{stringArrayType}, Output: stringArrayType},
        Definition{Inputs: []interface{}{intArrayType}, Output: intArrayType},
        Definition{Inputs: []interface{}{interfaceArrayType}, Output: interfaceArrayType},
    },
    Function: flatten,
}

Flatten is a function that flattens an array of arrays

- flatten([]interface{[]interface{"a", "b"},[]interface{"c", "d"}}) == []interface{}{"a","b","c","d"}
var Fold = Function{
    Name:    "Fold",
    Aliases: []string{"fold"},
    Definitions: []Definition{
        Definition{Inputs: []interface{}{reflect.String}, Output: reflect.String},
    },
    Function: fold,
}
var Format = Function{
    Name:    "Format",
    Aliases: []string{"format"},
    Definitions: []Definition{
        Definition{Inputs: []interface{}{timeType, reflect.String}, Output: reflect.String},
    },
    Function: format,
}
var Functions = []Function{
    Add,
    Base,
    Bottom,
    BoundingBox,
    Clean,
    Coalesce,
    Concat,
    Divide,
    First,
    Flatten,
    Fold,
    Format,
    GetLength,
    In,
    IIn,
    Intersects,
    Join,
    JSON,
    Last,
    Limit,
    Lookup,
    Max,
    Mean,
    Min,
    Multiply,
    Now,
    Prefix,
    Pow,
    Repeat,
    Replace,
    Second,
    Slice,
    Split,
    Sort,
    Stringify,
    Subtract,
    Suffix,
    Sum,
    TileX,
    TileY,
    ToArray,
    ToBigEndian,
    ToBytes,
    ToInt,
    ToInt8,
    ToInt16,
    ToInt32,
    ToInt64,
    ToIntArray,
    ToFloat32,
    ToFloat64,
    ToFloat64Array,
    ToItems,
    ToKeys,
    ToLittleEndian,
    ToLower,
    ToSet,
    ToString,
    ToStringSet,
    ToTitle,
    ToTime,
    Top,
    ToUpper,
    ToValues,
    Trim,
    Within,
}

Functions is an array of all the adapative functions defined in this package.

var GetLength = Function{
    Name:    "GetLength",
    Aliases: []string{"len"},
    Definitions: []Definition{
        Definition{
            Inputs: []interface{}{reflect.Array},
            Output: reflect.Int,
        },
        Definition{
            Inputs: []interface{}{reflect.Slice},
            Output: reflect.Int,
        },
        Definition{
            Inputs: []interface{}{reflect.Map},
            Output: reflect.Int,
        },
        Definition{
            Inputs: []interface{}{reflect.String},
            Output: reflect.Int,
        },
    },
    Function: getLength,
}
var IIn = Function{
    Name:    "IIn",
    Aliases: []string{"iin"},
    Definitions: []Definition{
        Definition{Inputs: []interface{}{reflect.String, reflect.String}, Output: reflect.Bool},
        Definition{Inputs: []interface{}{reflect.String, reflect.Array}, Output: reflect.Bool},
        Definition{Inputs: []interface{}{reflect.String, reflect.Slice}, Output: reflect.Bool},
        Definition{Inputs: []interface{}{reflect.String, reflect.Map}, Output: reflect.Bool},
        Definition{Inputs: []interface{}{reflect.String, reflect.Struct}, Output: reflect.Bool},
        Definition{Inputs: []interface{}{stringArrayType, stringArrayType}, Output: reflect.Bool},
    },
    Function: iin,
}
var In = Function{
    Name:    "In",
    Aliases: []string{"in"},
    Definitions: []Definition{
        Definition{Inputs: []interface{}{ipType, ipNetType}, Output: reflect.Bool},
        Definition{Inputs: []interface{}{ipType, ipNetPtrType}, Output: reflect.Bool},
        Definition{Inputs: []interface{}{reflect.String, reflect.String}, Output: reflect.Bool},
        Definition{Inputs: []interface{}{intArrayType, intArrayType}, Output: reflect.Bool},
        Definition{Inputs: []interface{}{stringArrayType, stringArrayType}, Output: reflect.Bool},
        Definition{Inputs: []interface{}{byteArrayType, byteArrayType}, Output: reflect.Bool},
        Definition{Inputs: []interface{}{reflect.String, reflect.Array}, Output: reflect.Bool},
        Definition{Inputs: []interface{}{reflect.String, reflect.Slice}, Output: reflect.Bool},
        Definition{Inputs: []interface{}{reflect.String, reflect.Map}, Output: reflect.Bool},
        Definition{Inputs: []interface{}{reflect.String, reflect.Struct}, Output: reflect.Bool},
    },
    Function: in,
}
var Intersects = Function{
    Name:    "intersects",
    Aliases: []string{"intersects"},
    Definitions: []Definition{
        Definition{Inputs: []interface{}{reflect.Map, reflect.Map}, Output: boolType},
        Definition{Inputs: []interface{}{float64ArrayType, float64ArrayType}, Output: boolType},
    },
    Function: intersects,
}
var JSON = Function{
    Name:    "json",
    Aliases: []string{"json"},
    Definitions: []Definition{
        Definition{Inputs: []interface{}{nil}, Output: reflect.String},
    },
    Function: func(args []interface{}) (interface{}, error) {
        if len(args) != 1 {
            return nil, &ErrorInvalidArguments{Function: "Json", Arguments: args}
        }
        out, err := json.Marshal(args[0])
        if err != nil {
            return err, errors.Wrap(err, "error marshaling to json")
        }
        return out, nil
    },
}
var Join = Function{
    Name:    "Join",
    Aliases: []string{"join"},
    Definitions: []Definition{
        Definition{Inputs: []interface{}{stringArrayType, reflect.String}, Output: reflect.String},
        Definition{Inputs: []interface{}{interfaceArrayType, reflect.String}, Output: reflect.String},
        Definition{Inputs: []interface{}{stringSetType, reflect.String}, Output: reflect.String},
    },
    Function: join,
}
var Last = Function{
    Name:    "Last",
    Aliases: []string{"last"},
    Definitions: []Definition{
        Definition{Inputs: []interface{}{byteArrayType}, Output: reflect.Uint8},
        Definition{Inputs: []interface{}{uint8ArrayType}, Output: reflect.Uint8},
        Definition{Inputs: []interface{}{intArrayType}, Output: reflect.Int},
        Definition{Inputs: []interface{}{int64ArrayType}, Output: reflect.Int64},
        Definition{Inputs: []interface{}{float64ArrayType}, Output: reflect.Float64},
        Definition{Inputs: []interface{}{stringArrayType}, Output: reflect.String},
        Definition{Inputs: []interface{}{stringIntMapSliceType}, Output: stringIntMapType},
        Definition{Inputs: []interface{}{interfaceArrayType}, Output: nil},
        Definition{Inputs: []interface{}{reflect.String}, Output: reflect.Uint8},
    },
    Function: last,
}
var Limit = Function{
    Name:    "Limit",
    Aliases: []string{"limit"},
    Definitions: []Definition{
        Definition{
            Inputs: []interface{}{reflect.Array, reflect.Int},
            Output: reflect.Slice,
        },
        Definition{
            Inputs: []interface{}{reflect.Slice, reflect.Int},
            Output: reflect.Slice,
        },
    },
    Function: limit,
}
var Lookup = Function{
    Name:    "Lookup",
    Aliases: []string{"lookup"},
    Definitions: []Definition{
        Definition{Inputs: []interface{}{reflect.Array, nil}, Output: nil},
        Definition{Inputs: []interface{}{reflect.Array, nil, nil}, Output: nil},
        Definition{Inputs: []interface{}{reflect.Slice, nil}, Output: nil},
        Definition{Inputs: []interface{}{reflect.Slice, nil, nil}, Output: nil},
        Definition{Inputs: []interface{}{reflect.Map, nil}, Output: nil},
        Definition{Inputs: []interface{}{reflect.Map, nil, nil}, Output: nil},
    },
    Function: lookup,
}
var Max = Function{
    Name:    "Max",
    Aliases: []string{"max"},
    Definitions: []Definition{
        Definition{Inputs: []interface{}{reflect.Int, reflect.Int}, Output: reflect.Int},
        Definition{Inputs: []interface{}{reflect.Int64, reflect.Int64}, Output: reflect.Int64},
        Definition{Inputs: []interface{}{reflect.Float64, reflect.Float64}, Output: reflect.Float64},
        Definition{Inputs: []interface{}{uint8ArrayType}, Output: reflect.Uint8},
        Definition{Inputs: []interface{}{intArrayType}, Output: reflect.Int},
        Definition{Inputs: []interface{}{int64ArrayType}, Output: reflect.Int64},
        Definition{Inputs: []interface{}{float64ArrayType}, Output: reflect.Float64},
    },
    Function: max,
}
var Mean = Function{
    Name:    "Mean",
    Aliases: []string{"mean"},
    Definitions: []Definition{
        Definition{Inputs: []interface{}{uint8ArrayType}, Output: reflect.Float64},
        Definition{Inputs: []interface{}{intArrayType}, Output: reflect.Float64},
        Definition{Inputs: []interface{}{int64ArrayType}, Output: reflect.Float64},
        Definition{Inputs: []interface{}{float64ArrayType}, Output: reflect.Float64},
    },
    Function: mean,
}
var Min = Function{
    Name:    "Min",
    Aliases: []string{"min"},
    Definitions: []Definition{
        Definition{Inputs: []interface{}{reflect.Int, reflect.Int}, Output: reflect.Int},
        Definition{Inputs: []interface{}{reflect.Int64, reflect.Int64}, Output: reflect.Int64},
        Definition{Inputs: []interface{}{reflect.Float64, reflect.Float64}, Output: reflect.Float64},
        Definition{Inputs: []interface{}{timeType, timeType}, Output: timeType},
        Definition{Inputs: []interface{}{intArrayType}, Output: reflect.Int},
        Definition{Inputs: []interface{}{int64ArrayType}, Output: reflect.Int64},
        Definition{Inputs: []interface{}{float64ArrayType}, Output: reflect.Float64},
    },
    Function: min,
}
var Multiply = Function{
    Name:    "Multiply",
    Aliases: []string{"multiply", "mul"},
    Definitions: []Definition{
        Definition{Inputs: []interface{}{reflect.Int, reflect.Int}, Output: reflect.Int},
        Definition{Inputs: []interface{}{reflect.Int, reflect.Int32}, Output: reflect.Int},
        Definition{Inputs: []interface{}{reflect.Int, reflect.Int64}, Output: reflect.Int},
        Definition{Inputs: []interface{}{reflect.Int, reflect.Float64}, Output: reflect.Float64},
        Definition{Inputs: []interface{}{reflect.Int32, reflect.Int}, Output: reflect.Int},
        Definition{Inputs: []interface{}{reflect.Int32, reflect.Int32}, Output: reflect.Int32},
        Definition{Inputs: []interface{}{reflect.Int32, reflect.Int64}, Output: reflect.Int64},
        Definition{Inputs: []interface{}{reflect.Int32, reflect.Float64}, Output: reflect.Float64},
        Definition{Inputs: []interface{}{reflect.Int64, reflect.Int}, Output: reflect.Int64},
        Definition{Inputs: []interface{}{reflect.Int64, reflect.Int32}, Output: reflect.Int64},
        Definition{Inputs: []interface{}{reflect.Int64, reflect.Int64}, Output: reflect.Int64},
        Definition{Inputs: []interface{}{reflect.Int64, reflect.Float64}, Output: reflect.Float64},
        Definition{Inputs: []interface{}{reflect.Float64, reflect.Int}, Output: reflect.Int},
        Definition{Inputs: []interface{}{reflect.Float64, reflect.Int32}, Output: reflect.Int},
        Definition{Inputs: []interface{}{reflect.Float64, reflect.Int64}, Output: reflect.Int},
        Definition{Inputs: []interface{}{reflect.Float64, reflect.Float64}, Output: reflect.Float64},
    },
    Function: multiply,
}
var Now = Function{
    Name:    "Now",
    Aliases: []string{"now"},
    Definitions: []Definition{
        Definition{Inputs: make([]interface{}, 0), Output: timeType},
    },
    Function: func(args []interface{}) (interface{}, error) {
        if len(args) != 0 {
            return nil, &ErrorInvalidArguments{Function: "Now", Arguments: args}
        }
        return time.Now(), nil
    },
}
var Pow = Function{
    Name:    "Pow",
    Aliases: []string{"pow"},
    Definitions: []Definition{
        Definition{Inputs: []interface{}{reflect.Int, reflect.Int}, Output: reflect.Float64},
        Definition{Inputs: []interface{}{reflect.Int, reflect.Int32}, Output: reflect.Float64},
        Definition{Inputs: []interface{}{reflect.Int, reflect.Int64}, Output: reflect.Float64},
        Definition{Inputs: []interface{}{reflect.Int, reflect.Float64}, Output: reflect.Float64},
        Definition{Inputs: []interface{}{reflect.Int32, reflect.Int}, Output: reflect.Float64},
        Definition{Inputs: []interface{}{reflect.Int32, reflect.Int32}, Output: reflect.Float64},
        Definition{Inputs: []interface{}{reflect.Int32, reflect.Int64}, Output: reflect.Float64},
        Definition{Inputs: []interface{}{reflect.Int32, reflect.Float64}, Output: reflect.Float64},
        Definition{Inputs: []interface{}{reflect.Int64, reflect.Int}, Output: reflect.Float64},
        Definition{Inputs: []interface{}{reflect.Int64, reflect.Int32}, Output: reflect.Float64},
        Definition{Inputs: []interface{}{reflect.Int64, reflect.Int64}, Output: reflect.Float64},
        Definition{Inputs: []interface{}{reflect.Int64, reflect.Float64}, Output: reflect.Float64},
        Definition{Inputs: []interface{}{reflect.Float64, reflect.Int}, Output: reflect.Float64},
        Definition{Inputs: []interface{}{reflect.Float64, reflect.Int32}, Output: reflect.Float64},
        Definition{Inputs: []interface{}{reflect.Float64, reflect.Int64}, Output: reflect.Float64},
        Definition{Inputs: []interface{}{reflect.Float64, reflect.Float64}, Output: reflect.Float64},
    },
    Function: pow,
}
var Prefix = Function{
    Name:    "Prefix",
    Aliases: []string{"prefix"},
    Definitions: []Definition{
        Definition{Inputs: []interface{}{reflect.String, reflect.String}, Output: reflect.Bool},
        Definition{Inputs: []interface{}{reflect.Array, reflect.Array}, Output: reflect.Bool},
        Definition{Inputs: []interface{}{reflect.Array, reflect.Slice}, Output: reflect.Bool},
        Definition{Inputs: []interface{}{reflect.Slice, reflect.Array}, Output: reflect.Bool},
        Definition{Inputs: []interface{}{reflect.Slice, reflect.Slice}, Output: reflect.Bool},
    },
    Function: prefix,
}
var Repeat = Function{
    Name:    "Repeat",
    Aliases: []string{"repeat"},
    Definitions: []Definition{
        Definition{
            Inputs: []interface{}{reflect.Array, reflect.Int},
            Output: reflect.Array,
        },
        Definition{
            Inputs: []interface{}{reflect.Slice, reflect.Int},
            Output: reflect.Slice,
        },
        Definition{
            Inputs: []interface{}{reflect.String, reflect.Int},
            Output: reflect.String,
        },
        Definition{
            Inputs: []interface{}{reflect.Uint8, reflect.Int},
            Output: reflect.Slice,
        },
    },
    Function: repeat,
}
var Replace = Function{
    Name:    "Replace",
    Aliases: []string{"replace"},
    Definitions: []Definition{
        Definition{Inputs: []interface{}{reflect.String, reflect.String, reflect.String}, Output: reflect.String},
    },
    Function: replace,
}
var Second = Function{
    Name:    "Second",
    Aliases: []string{"second"},
    Definitions: []Definition{
        Definition{Inputs: []interface{}{byteArrayType}, Output: reflect.Uint8},
        Definition{Inputs: []interface{}{uint8ArrayType}, Output: reflect.Uint8},
        Definition{Inputs: []interface{}{intArrayType}, Output: reflect.Int},
        Definition{Inputs: []interface{}{int64ArrayType}, Output: reflect.Int64},
        Definition{Inputs: []interface{}{float64ArrayType}, Output: reflect.Float64},
        Definition{Inputs: []interface{}{stringArrayType}, Output: reflect.String},
        Definition{Inputs: []interface{}{stringIntMapSliceType}, Output: stringIntMapType},
        Definition{Inputs: []interface{}{interfaceArrayType}, Output: nil},
        Definition{Inputs: []interface{}{reflect.String}, Output: reflect.Uint8},
    },
    Function: second,
}
var Slice = Function{
    Name:    "Slice",
    Aliases: []string{"slice"},
    Definitions: []Definition{
        Definition{Inputs: []interface{}{reflect.Array, intType}, Output: reflect.Slice},
        Definition{Inputs: []interface{}{reflect.Array, intType, intType}, Output: reflect.Slice},
        Definition{Inputs: []interface{}{reflect.Slice, intType}, Output: reflect.Slice},
        Definition{Inputs: []interface{}{reflect.Slice, intType, intType}, Output: reflect.Slice},
        Definition{Inputs: []interface{}{reflect.String, intType}, Output: reflect.String},
        Definition{Inputs: []interface{}{reflect.String, intType, intType}, Output: reflect.String},
    },
    Function: func(args []interface{}) (interface{}, error) {
        if len(args) == 2 {
            if start, ok := args[1].(int); ok {
                v := reflect.ValueOf(args[0])
                switch v.Type().Kind() {
                case reflect.Array, reflect.Slice, reflect.String:
                    return v.Slice(start, v.Len()).Interface(), nil
                }
            }
        } else if len(args) == 3 {
            if start, ok := args[1].(int); ok {
                if end, ok := args[2].(int); ok {
                    v := reflect.ValueOf(args[0])
                    switch v.Type().Kind() {
                    case reflect.Array, reflect.Slice, reflect.String:
                        return v.Slice(start, end).Interface(), nil
                    }
                }
            }
        }
        return nil, &ErrorInvalidArguments{Function: "Slice", Arguments: args}
    },
}
var Sort = Function{
    Name:    "Sort",
    Aliases: []string{"sort"},
    Definitions: []Definition{
        Definition{Inputs: []interface{}{stringArrayType}, Output: stringArrayType},
        Definition{Inputs: []interface{}{intArrayType}, Output: intArrayType},
        Definition{Inputs: []interface{}{stringArrayType, boolType}, Output: stringArrayType},
        Definition{Inputs: []interface{}{intArrayType, boolType}, Output: intArrayType},
    },
    Function: sortArray,
}
var Split = Function{
    Name:    "Split",
    Aliases: []string{"split"},
    Definitions: []Definition{
        Definition{Inputs: []interface{}{stringType, stringType}, Output: reflect.Slice},
        Definition{Inputs: []interface{}{stringType, stringType, intType}, Output: reflect.Slice},
    },
    Function: func(args []interface{}) (interface{}, error) {
        if str, ok := args[0].(string); ok {
            if delim, ok := args[1].(string); ok {
                if len(args) == 2 {
                    return strings.Split(str, delim), nil
                } else if len(args) == 3 {
                    if n, ok := args[2].(int); ok {
                        return strings.SplitN(str, delim, n), nil
                    }
                }
            }
        }
        return nil, &ErrorInvalidArguments{Function: "Split", Arguments: args}
    },
}
var Stringify = Function{
    Name:    "Stringify",
    Aliases: []string{"stringify"},
    Definitions: []Definition{
        Definition{Inputs: []interface{}{nil}, Output: nil},
    },
    Function: func(args []interface{}) (interface{}, error) {
        if len(args) != 1 {
            return nil, &ErrorInvalidArguments{Function: "Stringify", Arguments: args}
        }
        return stringify.StringifyMapKeys(args[0]), nil
    },
}
var Subtract = Function{
    Name:    "Subtract",
    Aliases: []string{"subtract", "sub"},
    Definitions: []Definition{
        Definition{Inputs: []interface{}{reflect.Int, reflect.Int}, Output: reflect.Int},
        Definition{Inputs: []interface{}{reflect.Int, reflect.Int32}, Output: reflect.Int},
        Definition{Inputs: []interface{}{reflect.Int, reflect.Int64}, Output: reflect.Int64},
        Definition{Inputs: []interface{}{reflect.Int, reflect.Float64}, Output: reflect.Float64},
        Definition{Inputs: []interface{}{reflect.Int64, reflect.Int}, Output: reflect.Int},
        Definition{Inputs: []interface{}{reflect.Int64, reflect.Int64}, Output: reflect.Int},
        Definition{Inputs: []interface{}{reflect.Int64, reflect.Float64}, Output: reflect.Float64},
        Definition{Inputs: []interface{}{reflect.Float64, reflect.Int}, Output: reflect.Int},
        Definition{Inputs: []interface{}{reflect.Float64, reflect.Int64}, Output: reflect.Int},
        Definition{Inputs: []interface{}{reflect.Float64, reflect.Float64}, Output: reflect.Float64},
        Definition{Inputs: []interface{}{reflect.Map, reflect.Map}, Output: reflect.Map},
    },
    Function: subtract,
}
var Suffix = Function{
    Name:    "Suffix",
    Aliases: []string{"suffix"},
    Definitions: []Definition{
        Definition{Inputs: []interface{}{reflect.String, reflect.String}, Output: reflect.Bool},
        Definition{Inputs: []interface{}{reflect.Array, reflect.Array}, Output: reflect.Bool},
        Definition{Inputs: []interface{}{reflect.Array, reflect.Slice}, Output: reflect.Bool},
        Definition{Inputs: []interface{}{reflect.Slice, reflect.Array}, Output: reflect.Bool},
        Definition{Inputs: []interface{}{reflect.Slice, reflect.Slice}, Output: reflect.Bool},
    },
    Function: suffix,
}
var Sum = Function{
    Name:    "Sum",
    Aliases: []string{"sum"},
    Definitions: []Definition{
        Definition{Inputs: []interface{}{uint8ArrayType}, Output: reflect.Uint8},
        Definition{Inputs: []interface{}{intArrayType}, Output: reflect.Int},
        Definition{Inputs: []interface{}{int64ArrayType}, Output: reflect.Int64},
        Definition{Inputs: []interface{}{float64ArrayType}, Output: reflect.Float64},
    },
    Function: sum,
}
var TileX = Function{
    Name:    "TileX",
    Aliases: []string{"tileX"},
    Definitions: []Definition{
        Definition{Inputs: []interface{}{float64Type, intType}, Output: intType},
        Definition{Inputs: []interface{}{intType, intType}, Output: intType},
    },
    Function: tileX,
}
var TileY = Function{
    Name:    "TileY",
    Aliases: []string{"tileY"},
    Definitions: []Definition{
        Definition{Inputs: []interface{}{float64Type, intType}, Output: intType},
        Definition{Inputs: []interface{}{intType, intType}, Output: intType},
    },
    Function: tileY,
}
var ToArray = Function{
    Name:    "ToArray",
    Aliases: []string{"array"},
    Definitions: []Definition{
        Definition{Inputs: []interface{}{stringSetType}, Output: stringArrayType},
        Definition{Inputs: []interface{}{intSetType}, Output: intArrayType},
        Definition{Inputs: []interface{}{interfaceSetType}, Output: interfaceArrayType},
        Definition{Inputs: []interface{}{reflect.Map}, Output: interface2DArrayType},
    },
    Function: toArray,
}
var ToBigEndian = Function{
    Name:    "ToBigEndian",
    Aliases: []string{"big"},
    Definitions: []Definition{
        Definition{Inputs: []interface{}{intType}, Output: byteArrayType},
        Definition{Inputs: []interface{}{int8Type}, Output: byteArrayType},
        Definition{Inputs: []interface{}{int16Type}, Output: byteArrayType},
        Definition{Inputs: []interface{}{int32Type}, Output: byteArrayType},
        Definition{Inputs: []interface{}{int64Type}, Output: byteArrayType},
    },
    Function: toBigEndian,
}
var ToBytes = Function{
    Name:    "ToBytes",
    Aliases: []string{"bytes"},
    Definitions: []Definition{
        Definition{
            Inputs: []interface{}{byteType},
            Output: byteArrayType,
        },
        Definition{
            Inputs: []interface{}{byteArrayType},
            Output: byteArrayType,
        },
        Definition{
            Inputs: []interface{}{stringType},
            Output: byteArrayType,
        },
    },
    Function: toBytes,
}
var ToFloat32 = Function{
    Name:    "ToFloat32",
    Aliases: []string{"float32"},
    Definitions: []Definition{
        Definition{Inputs: []interface{}{intType}, Output: float32Type},
        Definition{Inputs: []interface{}{int8Type}, Output: float32Type},
        Definition{Inputs: []interface{}{int16Type}, Output: float32Type},
        Definition{Inputs: []interface{}{int32Type}, Output: float32Type},
        Definition{Inputs: []interface{}{int64Type}, Output: float32Type},
        Definition{Inputs: []interface{}{float32Type}, Output: float32Type},
        Definition{Inputs: []interface{}{float64Type}, Output: float32Type},
        Definition{Inputs: []interface{}{reflect.String}, Output: float32Type},
    },
    Function: toFloat32,
}
var ToFloat64 = Function{
    Name:    "ToFloat64",
    Aliases: []string{"float64"},
    Definitions: []Definition{
        Definition{Inputs: []interface{}{intType}, Output: float64Type},
        Definition{Inputs: []interface{}{int8Type}, Output: float64Type},
        Definition{Inputs: []interface{}{int16Type}, Output: float64Type},
        Definition{Inputs: []interface{}{int32Type}, Output: float64Type},
        Definition{Inputs: []interface{}{int64Type}, Output: float64Type},
        Definition{Inputs: []interface{}{float64Type}, Output: float64Type},
        Definition{Inputs: []interface{}{reflect.String}, Output: float64Type},
    },
    Function: toFloat64,
}
var ToFloat64Array = Function{
    Name:    "Float64Array",
    Aliases: []string{"float64Array"},
    Definitions: []Definition{
        Definition{Inputs: []interface{}{reflect.Array}, Output: float64ArrayType},
        Definition{Inputs: []interface{}{reflect.Slice}, Output: float64ArrayType},
    },
    Function: float64Array,
}
var ToInt = Function{
    Name:    "ToInt",
    Aliases: []string{"int"},
    Definitions: []Definition{
        Definition{Inputs: []interface{}{intType}, Output: intType},
        Definition{Inputs: []interface{}{int8Type}, Output: intType},
        Definition{Inputs: []interface{}{int16Type}, Output: intType},
        Definition{Inputs: []interface{}{int32Type}, Output: intType},
        Definition{Inputs: []interface{}{int64Type}, Output: intType},
        Definition{Inputs: []interface{}{float32Type}, Output: intType},
        Definition{Inputs: []interface{}{float64Type}, Output: intType},
        Definition{Inputs: []interface{}{reflect.String}, Output: intType},
    },
    Function: toInt,
}
var ToInt16 = Function{
    Name:    "ToInt16",
    Aliases: []string{"int16"},
    Definitions: []Definition{
        Definition{Inputs: []interface{}{intType}, Output: int16Type},
        Definition{Inputs: []interface{}{int8Type}, Output: int16Type},
        Definition{Inputs: []interface{}{int16Type}, Output: int16Type},
        Definition{Inputs: []interface{}{int32Type}, Output: int16Type},
        Definition{Inputs: []interface{}{int64Type}, Output: int16Type},
        Definition{Inputs: []interface{}{reflect.String}, Output: int16Type},
    },
    Function: toInt16,
}
var ToInt32 = Function{
    Name:    "ToInt32",
    Aliases: []string{"int32"},
    Definitions: []Definition{
        Definition{Inputs: []interface{}{intType}, Output: int32Type},
        Definition{Inputs: []interface{}{int8Type}, Output: int32Type},
        Definition{Inputs: []interface{}{int16Type}, Output: int32Type},
        Definition{Inputs: []interface{}{int32Type}, Output: int32Type},
        Definition{Inputs: []interface{}{int64Type}, Output: int32Type},
        Definition{Inputs: []interface{}{float32Type}, Output: int32Type},
        Definition{Inputs: []interface{}{float64Type}, Output: int32Type},
        Definition{Inputs: []interface{}{reflect.String}, Output: int32Type},
    },
    Function: toInt32,
}
var ToInt64 = Function{
    Name:    "ToInt64",
    Aliases: []string{"int64"},
    Definitions: []Definition{
        Definition{Inputs: []interface{}{intType}, Output: int64Type},
        Definition{Inputs: []interface{}{int8Type}, Output: int64Type},
        Definition{Inputs: []interface{}{int16Type}, Output: int64Type},
        Definition{Inputs: []interface{}{int32Type}, Output: int64Type},
        Definition{Inputs: []interface{}{int64Type}, Output: int64Type},
        Definition{Inputs: []interface{}{float32Type}, Output: int64Type},
        Definition{Inputs: []interface{}{float64Type}, Output: int64Type},
        Definition{Inputs: []interface{}{reflect.String}, Output: int64Type},
    },
    Function: toInt64,
}
var ToInt8 = Function{
    Name:    "ToInt8",
    Aliases: []string{"int8"},
    Definitions: []Definition{
        Definition{Inputs: []interface{}{intType}, Output: int8Type},
        Definition{Inputs: []interface{}{int8Type}, Output: int8Type},
        Definition{Inputs: []interface{}{int16Type}, Output: int8Type},
        Definition{Inputs: []interface{}{int32Type}, Output: int8Type},
        Definition{Inputs: []interface{}{int64Type}, Output: int8Type},
        Definition{Inputs: []interface{}{reflect.String}, Output: int8Type},
    },
    Function: toInt8,
}
var ToIntArray = Function{
    Name:    "IntArray",
    Aliases: []string{"intArray"},
    Definitions: []Definition{
        Definition{Inputs: []interface{}{reflect.Array}, Output: intArrayType},
        Definition{Inputs: []interface{}{reflect.Slice}, Output: intArrayType},
    },
    Function: intArray,
}
var ToItems = Function{
    Name:    "ToItems",
    Aliases: []string{"items"},
    Definitions: []Definition{
        Definition{
            Inputs: []interface{}{reflect.Map},
            Output: reflect.Slice,
        },
    },
    Function: toItems,
}
var ToKeys = Function{
    Name:    "ToKeys",
    Aliases: []string{"keys"},
    Definitions: []Definition{
        Definition{
            Inputs: []interface{}{reflect.Map},
            Output: reflect.Slice,
        },
    },
    Function: toKeys,
}
var ToLittleEndian = Function{
    Name:    "ToLittleEndian",
    Aliases: []string{"little"},
    Definitions: []Definition{
        Definition{Inputs: []interface{}{intType}, Output: byteArrayType},
        Definition{Inputs: []interface{}{int8Type}, Output: byteArrayType},
        Definition{Inputs: []interface{}{int16Type}, Output: byteArrayType},
        Definition{Inputs: []interface{}{int32Type}, Output: byteArrayType},
        Definition{Inputs: []interface{}{int64Type}, Output: byteArrayType},
    },
    Function: toLittleEndian,
}
var ToLower = Function{
    Name:    "ToLower",
    Aliases: []string{"lower"},
    Definitions: []Definition{
        Definition{Inputs: []interface{}{stringType}, Output: stringType},
        Definition{Inputs: []interface{}{byteArrayType}, Output: byteArrayType},
    },
    Function: toLower,
}
var ToSet = Function{
    Name:    "ToSet",
    Aliases: []string{"set"},
    Definitions: []Definition{
        Definition{Inputs: []interface{}{reflect.Slice}, Output: reflect.Map},
        Definition{Inputs: []interface{}{reflect.Map}, Output: reflect.Map},
    },
    Function: toSet,
}
var ToString = Function{
    Name:    "ToString",
    Aliases: []string{"string"},
    Definitions: []Definition{
        Definition{
            Inputs: []interface{}{byteType},
            Output: stringType,
        },
        Definition{
            Inputs: []interface{}{byteArrayType},
            Output: stringType,
        },
        Definition{
            Inputs: []interface{}{stringType},
            Output: stringType,
        },
    },
    Function: toString,
}
var ToStringArray = Function{
    Name:    "StringArray",
    Aliases: []string{"stringArray"},
    Definitions: []Definition{
        Definition{Inputs: []interface{}{reflect.Array}, Output: stringArrayType},
        Definition{Inputs: []interface{}{reflect.Slice}, Output: stringArrayType},
    },
    Function: stringArray,
}
var ToStringSet = Function{
    Name:    "ToStringSet",
    Aliases: []string{"stringSet"},
    Definitions: []Definition{
        Definition{Inputs: []interface{}{reflect.Slice}, Output: reflect.Map},
        Definition{Inputs: []interface{}{reflect.Map}, Output: stringSetType},
    },
    Function: stringSet,
}
var ToTime = Function{
    Name:    "ToTime",
    Aliases: []string{"time"},
    Definitions: []Definition{
        Definition{Inputs: []interface{}{stringType}, Output: timeType},
        Definition{Inputs: []interface{}{timeType}, Output: timeType},
    },
    Function: toTime,
}
var ToTitle = Function{
    Name:    "ToTitle",
    Aliases: []string{"title"},
    Definitions: []Definition{
        Definition{Inputs: []interface{}{stringType}, Output: stringType},
        Definition{Inputs: []interface{}{byteArrayType}, Output: byteArrayType},
    },
    Function: toTitle,
}
var ToUpper = Function{
    Name:    "ToUpper",
    Aliases: []string{"upper"},
    Definitions: []Definition{
        Definition{Inputs: []interface{}{stringType}, Output: stringType},
        Definition{Inputs: []interface{}{byteArrayType}, Output: byteArrayType},
    },
    Function: toUpper,
}
var ToValues = Function{
    Name:    "ToValues",
    Aliases: []string{"values"},
    Definitions: []Definition{
        Definition{
            Inputs: []interface{}{reflect.Map},
            Output: interfaceArrayType,
        },
    },
    Function: toValues,
}
var Top = Function{
    Name:    "Top",
    Aliases: []string{"top"},
    Definitions: []Definition{
        Definition{Inputs: []interface{}{stringIntMapType, intType}, Output: stringArrayType},
        Definition{Inputs: []interface{}{stringIntMapType, intType, intType}, Output: stringArrayType},
    },
    Function: top,
}
var Trim = Function{
    Name:    "Trim",
    Aliases: []string{"trim"},
    Definitions: []Definition{
        Definition{Inputs: []interface{}{reflect.String}, Output: reflect.String},
        Definition{Inputs: []interface{}{stringArrayType}, Output: reflect.String},
        Definition{Inputs: []interface{}{interfaceArrayType}, Output: reflect.String},
    },
    Function: trim,
}
var Within = Function{
    Name:    "Within",
    Aliases: []string{"within"},
    Definitions: []Definition{
        Definition{Inputs: []interface{}{float64ArrayType, float64ArrayType}, Output: reflect.Bool},
        Definition{Inputs: []interface{}{intArrayType, intArrayType}, Output: reflect.Bool},
    },
    Function: func(args []interface{}) (interface{}, error) {
        if coordinate, ok := args[0].([]float64); ok {
            if extent, ok := args[1].([]float64); ok {
                dims := len(coordinate)
                if dims*2 == len(extent) {
                    for i, x := range coordinate {
                        if x < extent[i] || x > extent[i+dims] {
                            return false, nil
                        }
                    }
                    return true, nil
                }
            }
        } else if coordinate, ok := args[0].([]int); ok {
            if extent, ok := args[1].([]int); ok {
                dims := len(coordinate)
                if dims*2 == len(extent) {
                    for i, x := range coordinate {
                        if x < extent[i] || x > extent[i+dims] {
                            return false, nil
                        }
                    }
                    return true, nil
                }
            }
        }
        return nil, &ErrorInvalidArguments{Function: "Within", Arguments: args}
    },
}

type Definition Uses

type Definition struct {
    Inputs []interface{} // an array of types or kinds
    Output interface{}   // the type or kind returned by the defined function
}

Definition is a struct containing a function definition

func (Definition) IsValid Uses

func (d Definition) IsValid(args []interface{}) bool

IsValid returns true if the args match the kinds or types or the definition.

type ErrorInvalidArguments Uses

type ErrorInvalidArguments struct {
    Function  string        // the name of the Function
    Arguments []interface{} // the arguments for the function
}

ErrorInvalidArguments is an error returned when a function is called with invalid arguments.

func (ErrorInvalidArguments) Error Uses

func (e ErrorInvalidArguments) Error() string

Error returns the error as a string.

type ErrorOverflow Uses

type ErrorOverflow struct {
    Original interface{}  // the original value
    Target   reflect.Type // the target type
}

ErrorOverflow is an error returned a number can't be converted to a lower bitsize.

func (ErrorOverflow) Error Uses

func (e ErrorOverflow) Error() string

ErrorOverflow returns the error as a string.

type Function Uses

type Function struct {
    Name        string                                        // the name of the function
    Description string                                        // a description of the function
    Aliases     []string                                      // aliases for the function used when providing a public API
    Definitions []Definition                                  // the definitions of the function
    Function    func(args []interface{}) (interface{}, error) // the underlying function to execute
}

Function is a struct used for giving an underlying function a name and definitions.

func (Function) IsValid Uses

func (f Function) IsValid(args []interface{}) bool

IsValid returns true if the arguments match a definition of the function.

func (Function) Map Uses

func (f Function) Map() map[string]interface{}

Map returns a map of metadata about the function.

func (Function) MustRun Uses

func (f Function) MustRun(args []interface{}) interface{}

MustRun executes the function with the provided arguments and returns the result. If there is any error, then panics.

func (Function) Run Uses

func (f Function) Run(args []interface{}) (interface{}, error)

Run executes the function with the provided arguments and returns the result, and error if any.

func (Function) Validate Uses

func (f Function) Validate(args []interface{}) error

Validate returns a ErrorInvalidArguments error if the arguments do not match a definition of the function.

func (Function) ValidateRun Uses

func (f Function) ValidateRun(args []interface{}) (interface{}, error)

ValidateRun validates the function arguments and then runs the function if valid.

type TestCase Uses

type TestCase struct {
    Inputs   []interface{} // the inputs to the function
    Function Function      // the function to evaluate
    Output   interface{}   // the result of the evaluation
}

TestCase is a struct containing the variables for a unit test of function evaluation

func NewTestCase Uses

func NewTestCase(inputs []interface{}, function Function, output interface{}) TestCase

NewTestCase returns a new TestCase

Package af imports 15 packages (graph) and is imported by 1 packages. Updated 2019-05-02. Refresh now. Tools for package owners.