1
0
mirror of https://github.com/MontFerret/ferret.git synced 2025-10-30 23:37:40 +02:00

Rewrite comments, closing #118

This commit is contained in:
3timeslazy
2018-10-14 20:06:27 +03:00
committed by Tim Voronov
parent 5db8df55db
commit 6df08a60cb
117 changed files with 715 additions and 878 deletions

View File

@@ -2,17 +2,16 @@ package arrays
import (
"context"
"github.com/MontFerret/ferret/pkg/runtime/core"
"github.com/MontFerret/ferret/pkg/runtime/values"
)
/*
* Appends a new item to an array and returns a new array with a given element.
* If ``uniqueOnly`` is set to true, then will add the item only if it's unique.
* @param arr (Array) - Target array.
* @param item (Read) - Target value to add.
* @returns arr (Array) - New array.
*/
// Append appends a new item to an array and returns a new array with a given element.
// If ``uniqueOnly`` is set to true, then will add the item only if it's unique.
// @param arr (Array) - Target array.
// @param item (Read) - Target value to add.
// @returns arr (Array) - New array.
func Append(_ context.Context, args ...core.Value) (core.Value, error) {
err := core.ValidateArgs(args, 2, 3)

View File

@@ -2,15 +2,14 @@ package arrays
import (
"context"
"github.com/MontFerret/ferret/pkg/runtime/core"
"github.com/MontFerret/ferret/pkg/runtime/values"
)
/*
* Returns a first element from a given array.
* @param arr (Array) - Target array.
* @returns element (Read) - First element in a given array.
*/
// First returns a first element from a given array.
// @param arr (Array) - Target array.
// @returns element (Read) - First element in a given array.
func First(_ context.Context, args ...core.Value) (core.Value, error) {
err := core.ValidateArgs(args, 1, 1)

View File

@@ -2,20 +2,19 @@ package arrays
import (
"context"
"github.com/MontFerret/ferret/pkg/runtime/core"
"github.com/MontFerret/ferret/pkg/runtime/values"
)
/*
* Turn an array of arrays into a flat array.
* All array elements in array will be expanded in the result array.
* Non-array elements are added as they are.
* The function will recurse into sub-arrays up to the specified depth.
* Duplicates will not be removed.
* @param arr (Array) - Target array.
* @param depth (Int, optional) - Depth level.
* @returns (Array) - Flat array.
*/
// Flatten turn an array of arrays into a flat array.
// All array elements in array will be expanded in the result array.
// Non-array elements are added as they are.
// The function will recurse into sub-arrays up to the specified depth.
// Duplicates will not be removed.
// @param arr (Array) - Target array.
// @param depth (Int, optional) - Depth level.
// @returns (Array) - Flat array.
func Flatten(_ context.Context, args ...core.Value) (core.Value, error) {
err := core.ValidateArgs(args, 1, 2)

View File

@@ -2,17 +2,16 @@ package arrays
import (
"context"
"github.com/MontFerret/ferret/pkg/runtime/core"
"github.com/MontFerret/ferret/pkg/runtime/values"
)
/*
* Return the intersection of all arrays specified.
* The result is an array of values that occur in all arguments.
* @param arrays (Array, repeated) - An arbitrary number of arrays as multiple arguments (at least 2).
* @returns (Array) - A single array with only the elements, which exist in all provided arrays.
* The element order is random. Duplicates are removed.
*/
// Intersection return the intersection of all arrays specified.
// The result is an array of values that occur in all arguments.
// @param arrays (Array, repeated) - An arbitrary number of arrays as multiple arguments (at least 2).
// @returns (Array) - A single array with only the elements, which exist in all provided arrays.
// The element order is random. Duplicates are removed.
func Intersection(_ context.Context, args ...core.Value) (core.Value, error) {
return sections(args, len(args))
}

View File

@@ -2,15 +2,14 @@ package arrays
import (
"context"
"github.com/MontFerret/ferret/pkg/runtime/core"
"github.com/MontFerret/ferret/pkg/runtime/values"
)
/*
* Returns the last element of an array.
* @param array (Array) - The target array.
* @returns (Read) - Last element of an array.
*/
// Last returns the last element of an array.
// @param array (Array) - The target array.
// @returns (Read) - Last element of an array.
func Last(_ context.Context, args ...core.Value) (core.Value, error) {
err := core.ValidateArgs(args, 1, 1)

View File

@@ -2,16 +2,15 @@ package arrays
import (
"context"
"github.com/MontFerret/ferret/pkg/runtime/core"
"github.com/MontFerret/ferret/pkg/runtime/values"
)
/*
* Return the difference of all arrays specified.
* @param arrays (Array, repeated) - An arbitrary number of arrays as multiple arguments (at least 2).
* @returns array (Array) - An array of values that occur in the first array, but not in any of the subsequent arrays.
* The order of the result array is undefined and should not be relied on. Duplicates will be removed.
*/
// Minus return the difference of all arrays specified.
// @param arrays (Array, repeated) - An arbitrary number of arrays as multiple arguments (at least 2).
// @returns array (Array) - An array of values that occur in the first array, but not in any of the subsequent arrays.
// The order of the result array is undefined and should not be relied on. Duplicates will be removed.
func Minus(_ context.Context, args ...core.Value) (core.Value, error) {
err := core.ValidateArgs(args, 2, core.MaxArgs)

View File

@@ -2,18 +2,17 @@ package arrays
import (
"context"
"github.com/MontFerret/ferret/pkg/runtime/core"
"github.com/MontFerret/ferret/pkg/runtime/values"
)
/*
* Returns the element of an array at a given position.
* It is the same as anyArray[position] for positive positions, but does not support negative positions.
* @param array (Array) - An array with elements of arbitrary type.
* @param index (Int) - Position of desired element in array, positions start at 0.
* @returns (Read) - The array element at the given position.
* If position is negative or beyond the upper bound of the array, then NONE will be returned.
*/
// Nth returns the element of an array at a given position.
// It is the same as anyArray[position] for positive positions, but does not support negative positions.
// @param array (Array) - An array with elements of arbitrary type.
// @param index (Int) - Position of desired element in array, positions start at 0.
// @returns (Read) - The array element at the given position.
// If position is negative or beyond the upper bound of the array, then NONE will be returned.
func Nth(_ context.Context, args ...core.Value) (core.Value, error) {
err := core.ValidateArgs(args, 2, 2)

View File

@@ -2,15 +2,14 @@ package arrays
import (
"context"
"github.com/MontFerret/ferret/pkg/runtime/core"
)
/*
* Return the values that occur only once across all arrays specified.
* @param arrays (Array, repeated) - An arbitrary number of arrays as multiple arguments (at least 2).
* @returns (Array) - A single array with only the elements that exist only once across all provided arrays.
* The element order is random.
*/
// Outersection return the values that occur only once across all arrays specified.
// @param arrays (Array, repeated) - An arbitrary number of arrays as multiple arguments (at least 2).
// @returns (Array) - A single array with only the elements that exist only once across all provided arrays.
// The element order is random.
func Outersection(_ context.Context, args ...core.Value) (core.Value, error) {
return sections(args, 1)
}

View File

@@ -2,15 +2,14 @@ package arrays
import (
"context"
"github.com/MontFerret/ferret/pkg/runtime/core"
"github.com/MontFerret/ferret/pkg/runtime/values"
)
/*
* Returns a new array without last element.
* @param array (Array) - Target array.
* @returns (Array) - Copy of an array without last element.
*/
// Pop returns a new array without last element.
// @param array (Array) - Target array.
// @returns (Array) - Copy of an array without last element.
func Pop(_ context.Context, args ...core.Value) (core.Value, error) {
err := core.ValidateArgs(args, 1, 1)

View File

@@ -2,16 +2,15 @@ package arrays
import (
"context"
"github.com/MontFerret/ferret/pkg/runtime/core"
"github.com/MontFerret/ferret/pkg/runtime/values"
)
/*
* Returns a value indicating whether an element is contained in array. Optionally returns its position.
* @param array (Array) - The source array.
* @param value (Read) - The target value.
* @param returnIndex (Boolean, optional) - Read which indicates whether to return item's position.
*/
// Position returns a value indicating whether an element is contained in array. Optionally returns its position.
// @param array (Array) - The source array.
// @param value (Read) - The target value.
// @param returnIndex (Boolean, optional) - Read which indicates whether to return item's position.
func Position(_ context.Context, args ...core.Value) (core.Value, error) {
err := core.ValidateArgs(args, 2, 3)

View File

@@ -2,17 +2,16 @@ package arrays
import (
"context"
"github.com/MontFerret/ferret/pkg/runtime/core"
"github.com/MontFerret/ferret/pkg/runtime/values"
)
/*
* Create a new array with appended value.
* @param array (Array) - Source array.
* @param value (Read) - Target value.
* @param unique (Boolean, optional) - Read indicating whether to do uniqueness check.
* @returns (Array) - A new array with appended value.
*/
// Push create a new array with appended value.
// @param array (Array) - Source array.
// @param value (Read) - Target value.
// @param unique (Boolean, optional) - Read indicating whether to do uniqueness check.
// @returns (Array) - A new array with appended value.
func Push(_ context.Context, args ...core.Value) (core.Value, error) {
err := core.ValidateArgs(args, 2, 3)

View File

@@ -2,16 +2,15 @@ package arrays
import (
"context"
"github.com/MontFerret/ferret/pkg/runtime/core"
"github.com/MontFerret/ferret/pkg/runtime/values"
)
/*
* Returns a new array without an element by a given position.
* @param array (Array) - Source array.
* @param position (Int) - Target element position.
* @return (Array) - A new array without an element by a given position.
*/
// RemoveNth returns a new array without an element by a given position.
// @param array (Array) - Source array.
// @param position (Int) - Target element position.
// @return (Array) - A new array without an element by a given position.
func RemoveNth(_ context.Context, args ...core.Value) (core.Value, error) {
err := core.ValidateArgs(args, 2, 2)

View File

@@ -2,18 +2,17 @@ package arrays
import (
"context"
"github.com/MontFerret/ferret/pkg/runtime/core"
"github.com/MontFerret/ferret/pkg/runtime/values"
)
/*
* Returns a new array with removed all occurrences of value in a given array.
* Optionally with a limit to the number of removals.
* @param array (Array) - Source array.
* @param value (Read) - Target value.
* @param limit (Int, optional) - A limit to the number of removals.
* @returns (Array) - A new array with removed all occurrences of value in a given array.
*/
// RemoveValue returns a new array with removed all occurrences of value in a given array.
// Optionally with a limit to the number of removals.
// @param array (Array) - Source array.
// @param value (Read) - Target value.
// @param limit (Int, optional) - A limit to the number of removals.
// @returns (Array) - A new array with removed all occurrences of value in a given array.
func RemoveValue(_ context.Context, args ...core.Value) (core.Value, error) {
err := core.ValidateArgs(args, 2, 3)

View File

@@ -2,16 +2,15 @@ package arrays
import (
"context"
"github.com/MontFerret/ferret/pkg/runtime/core"
"github.com/MontFerret/ferret/pkg/runtime/values"
)
/*
* Returns a new array with removed all occurrences of values in a given array.
* @param array (Array) - Source array.
* @param values (Array) - Target values.
* @returns (Array) - A new array with removed all occurrences of values in a given array.
*/
// RemoveValues returns a new array with removed all occurrences of values in a given array.
// @param array (Array) - Source array.
// @param values (Array) - Target values.
// @returns (Array) - A new array with removed all occurrences of values in a given array.
func RemoveValues(_ context.Context, args ...core.Value) (core.Value, error) {
err := core.ValidateArgs(args, 2, 2)

View File

@@ -2,15 +2,14 @@ package arrays
import (
"context"
"github.com/MontFerret/ferret/pkg/runtime/core"
"github.com/MontFerret/ferret/pkg/runtime/values"
)
/*
* Return a new array with its elements reversed.
* @param array (Array) - Target array.
* @returns (Array) - A new array with its elements reversed.
*/
// Reverse return a new array with its elements reversed.
// @param array (Array) - Target array.
// @returns (Array) - A new array with its elements reversed.
func Reverse(_ context.Context, args ...core.Value) (core.Value, error) {
err := core.ValidateArgs(args, 1, 1)

View File

@@ -2,15 +2,14 @@ package arrays
import (
"context"
"github.com/MontFerret/ferret/pkg/runtime/core"
"github.com/MontFerret/ferret/pkg/runtime/values"
)
/*
* Returns a new array without the first element.
* @param array (Array) - Target array.
* @returns (Array) - Copy of an array without the first element.
*/
// Shift returns a new array without the first element.
// @param array (Array) - Target array.
// @returns (Array) - Copy of an array without the first element.
func Shift(_ context.Context, args ...core.Value) (core.Value, error) {
err := core.ValidateArgs(args, 1, 1)

View File

@@ -2,17 +2,16 @@ package arrays
import (
"context"
"github.com/MontFerret/ferret/pkg/runtime/core"
"github.com/MontFerret/ferret/pkg/runtime/values"
)
/*
* Returns a new sliced array.
* @param array (Array) - Source array.
* @param start (Int) - Start position of extraction.
* @param length (Int, optional) - Read indicating how many elements to extract.
* @returns (Array) - Sliced array.
*/
// Slice returns a new sliced array.
// @param array (Array) - Source array.
// @param start (Int) - Start position of extraction.
// @param length (Int, optional) - Read indicating how many elements to extract.
// @returns (Array) - Sliced array.
func Slice(_ context.Context, args ...core.Value) (core.Value, error) {
err := core.ValidateArgs(args, 2, 3)

View File

@@ -2,17 +2,16 @@ package arrays
import (
"context"
"github.com/MontFerret/ferret/pkg/runtime/collections"
"github.com/MontFerret/ferret/pkg/runtime/core"
"github.com/MontFerret/ferret/pkg/runtime/values"
)
/*
* Sorts all elements in anyArray.
* The function will use the default comparison order for FQL value types.
* @param array (Array) - Target array.
* @returns (Array) - Sorted array.
*/
// Sorted sorts all elements in anyArray.
// The function will use the default comparison order for FQL value types.
// @param array (Array) - Target array.
// @returns (Array) - Sorted array.
func Sorted(_ context.Context, args ...core.Value) (core.Value, error) {
err := core.ValidateArgs(args, 1, 1)

View File

@@ -2,18 +2,17 @@ package arrays
import (
"context"
"github.com/MontFerret/ferret/pkg/runtime/collections"
"github.com/MontFerret/ferret/pkg/runtime/core"
"github.com/MontFerret/ferret/pkg/runtime/values"
)
/*
* Sorts all elements in anyArray.
* The function will use the default comparison order for FQL value types.
* Additionally, the values in the result array will be made unique
* @param array (Array) - Target array.
* @returns (Array) - Sorted array.
*/
// SortedUnique sorts all elements in anyArray.
// The function will use the default comparison order for FQL value types.
// Additionally, the values in the result array will be made unique
// @param array (Array) - Target array.
// @returns (Array) - Sorted array.
func SortedUnique(_ context.Context, args ...core.Value) (core.Value, error) {
err := core.ValidateArgs(args, 1, 1)

View File

@@ -2,15 +2,14 @@ package arrays
import (
"context"
"github.com/MontFerret/ferret/pkg/runtime/core"
"github.com/MontFerret/ferret/pkg/runtime/values"
)
/*
* Returns the union of all passed arrays.
* @param arrays (Array, repeated) - List of arrays to combine.
* @returns (Array) - All array elements combined in a single array, in any order.
*/
// Union returns the union of all passed arrays.
// @param arrays (Array, repeated) - List of arrays to combine.
// @returns (Array) - All array elements combined in a single array, in any order.
func Union(_ context.Context, args ...core.Value) (core.Value, error) {
err := core.ValidateArgs(args, 2, core.MaxArgs)

View File

@@ -2,17 +2,16 @@ package arrays_test
import (
"context"
"testing"
"github.com/MontFerret/ferret/pkg/runtime/values"
"github.com/MontFerret/ferret/pkg/stdlib/arrays"
. "github.com/smartystreets/goconvey/convey"
"testing"
)
/*
* Returns the union of distinct values of all passed arrays.
* @param arrays (Array, repeated) - List of arrays to combine.
* @returns (Array) - All array elements combined in a single array, without duplicates, in any order.
*/
// TestUnion returns the union of distinct values of all passed arrays.
// @param arrays (Array, repeated) - List of arrays to combine.
// @returns (Array) - All array elements combined in a single array, without duplicates, in any order.
func TestUnion(t *testing.T) {
Convey("Should union all arrays", t, func() {
arr1 := values.NewArrayWith(

View File

@@ -2,16 +2,15 @@ package arrays
import (
"context"
"github.com/MontFerret/ferret/pkg/runtime/collections"
"github.com/MontFerret/ferret/pkg/runtime/core"
"github.com/MontFerret/ferret/pkg/runtime/values"
)
/*
* Returns all unique elements from a given array.
* @param array (Array) - Target array.
* @returns (Array) - New array without duplicates.
*/
// Unique returns all unique elements from a given array.
// @param array (Array) - Target array.
// @returns (Array) - New array without duplicates.
func Unique(_ context.Context, args ...core.Value) (core.Value, error) {
err := core.ValidateArgs(args, 1, 1)

View File

@@ -2,18 +2,17 @@ package arrays
import (
"context"
"github.com/MontFerret/ferret/pkg/runtime/core"
"github.com/MontFerret/ferret/pkg/runtime/values"
)
/*
* Prepends value to a given array.
* @param array (Array) - Target array.
* @param value (Read) - Target value to prepend.
* @param unique (Boolean, optional) - Optional value indicating whether a value must be unique to be prepended.
* Default is false.
* @returns (Array) - New array with prepended value.
*/
// Unshift prepends value to a given array.
// @param array (Array) - Target array.
// @param value (Read) - Target value to prepend.
// @param unique (Boolean, optional) - Optional value indicating whether a value must be unique to be prepended.
// Default is false.
// @returns (Array) - New array with prepended value.
func Unshift(_ context.Context, args ...core.Value) (core.Value, error) {
err := core.ValidateArgs(args, 2, 3)