Logo GenPRES

Array Module

Picks, removes, prunes and formats the elements of an array and finds the median and the element nearest to a target.

Nested modules

Modules Description

Tests

Holds the Unquote tests of the Array functions.

Functions and values

Function or value Description

Array.allEqual succ fail xs

Full Usage: Array.allEqual succ fail xs

Parameters:
    succ : 'a -> 'b
    fail : 'b
    xs : 'a[]

Returns: 'b
Type parameters: 'a, 'b (requires equality)

Determine if all elements in an array are equal. Pass the distinct element to the succ function if all elements are equal, else return fail. Example: allEqual (fun x -> Some x) (fun () -> None) [|1;1;1|] -> Some 1

succ : 'a -> 'b
fail : 'b
xs : 'a[]
Returns: 'b

Array.allEqualToOpt xs

Full Usage: Array.allEqualToOpt xs

Parameters:
    xs : 'a[]

Returns: 'a option
Type parameters: 'a (requires equality)

Return an option of an element if all elements in an array are equal or return None

xs : 'a[]
Returns: 'a option

Array.allEqualToString xs

Full Usage: Array.allEqualToString xs

Parameters:
    xs : 'a[]

Returns: string
Type parameters: 'a (requires equality)

Return the string version of an element if all elements in an array are equal or return an empty string Example: allEqualToString [|1;1;1|] -> "1"

xs : 'a[]
Returns: string

Array.arrayFilter p xs

Full Usage: Array.arrayFilter p xs

Parameters:
    p : 'a -> bool
    xs : 'a array array

Returns: 'a array array
Type parameters: 'a

Filter an array of arrays using a predicate function p. The purpose of this function is to filter the elements of the input array xs based on the condition that at least one element in each subarray (inside xs) satisfies the predicate function p. Example: filterArrays (fun x -> x % 2 = 0) [|[|1;3|]; [|4;5;6|]; [|7;8;9|]|] -> [|[|4;5;6|]|]

p : 'a -> bool
xs : 'a array array
Returns: 'a array array

Array.collectArrays p xs

Full Usage: Array.collectArrays p xs

Parameters:
    p : 'a -> bool
    xs : 'a array array

Returns: 'a array
Type parameters: 'a

In summary, the collectArrays function filters the elements within each subarray using the predicate function p and then combines the filtered elements from all subarrays into a single array, effectively flattening the subarrays while applying the filtering criterion. Example: collectArrays (fun x -> x % 2 = 0) [|[|1;2;3|]; [|4;5;6|]; [|7;8;9|]|] -> [|2;4;6;8|]

p : 'a -> bool
xs : 'a array array
Returns: 'a array

Array.indices pred xs

Full Usage: Array.indices pred xs

Parameters:
    pred : 'a -> bool
    xs : 'a array

Returns: int array
Type parameters: 'a
pred : 'a -> bool
xs : 'a array
Returns: int array

Array.median xs

Full Usage: Array.median xs

Parameters:
    xs : int array

Returns: float
xs : int array
Returns: float

Array.nearestIndex x xs

Full Usage: Array.nearestIndex x xs

Parameters:
    x : ^a
    xs : ^b[]

Returns: int
Modifiers: inline
Type parameters: ^a, ^b, ^c (requires (static member op_Subtraction : ^a * ^b -> ^c) and (static member op_Subtraction : ^a * ^b -> ^c) and (static member Abs : ^c -> ^c) and comparison)

Get the nearest index in an array to a target value. Returns the index of the element that has the smallest absolute difference from the target. Throws an exception if the array is empty.

x : ^a
xs : ^b[]
Returns: int

Array.pickArray pl xs

Full Usage: Array.pickArray pl xs

Parameters:
    pl : int seq
    xs : 'a[]

Returns: 'a[]
Type parameters: 'a

Pick elements from an array using a list of indices pl0

pl : int seq
xs : 'a[]
Returns: 'a[]

Array.pickNearestHigherElseLower target xs

Full Usage: Array.pickNearestHigherElseLower target xs

Parameters:
    target : 'a
    xs : 'a array

Returns: 'a
Modifiers: inline
Type parameters: 'a (requires comparison)
target : 'a
xs : 'a array
Returns: 'a

Array.prepend xs1 xs2

Full Usage: Array.prepend xs1 xs2

Parameters:
    xs1 : 'a array
    xs2 : 'a array

Returns: 'a array
Type parameters: 'a

Prepend an array to another array Example: [|1;2|] |> prepend [|3;4|] -> [|1;2;3;4|]

xs1 : 'a array
xs2 : 'a array
Returns: 'a array

Array.prune maxLength xs

Full Usage: Array.prune maxLength xs

Parameters:
    maxLength : int
    xs : 'a array

Returns: 'a array
Type parameters: 'a

In summary, the prune function trims the input array xs by keeping its first and last elements, along with elements that are spaced out proportionally in between, such that the final length of the array doesn't exceed the specified maxLength. The spacing between the elements is controlled by the calculated step size d. Example: prune 5 [|1;2;3;4;5;6;7;8;9|] -> [|1; 4; 7; 9|]

maxLength : int
xs : 'a array
Returns: 'a array

Array.remove pred xs

Full Usage: Array.remove pred xs

Parameters:
    pred : 'a -> bool
    xs : 'a array

Returns: 'a array
Type parameters: 'a

Remove elements from an array using a predicate function pred.

pred : 'a -> bool
xs : 'a array
Returns: 'a array

Array.someIfOne _arg1

Full Usage: Array.someIfOne _arg1

Parameters:
    _arg1 : 'a[]

Returns: 'a option
Type parameters: 'a

Return an option of an element if the array contains exactly one element or return None

_arg1 : 'a[]
Returns: 'a option

Array.toReadableString xs

Full Usage: Array.toReadableString xs

Parameters:
    xs : 'a[]

Returns: string
Modifiers: inline
Type parameters: 'a

Convert an array to a string using a left and right delimiter Left = empty string, right = empty string, del = ; Example: toReadableString [|1;2;3|] -> "1;2;3"

xs : 'a[]
Returns: string

Array.toString xs

Full Usage: Array.toString xs

Parameters:
    xs : 'a[]

Returns: string
Modifiers: inline
Type parameters: 'a

Convert an array to a string using a left and right delimiter left = [|, right = |], del = ; Example: toString [|1;2;3|] -> "[|1;2;3|]"

xs : 'a[]
Returns: string

Array.toString_ left right del xs

Full Usage: Array.toString_ left right del xs

Parameters:
    left : string
    right : string
    del : 'a
    xs : 'b[]

Returns: string
Modifiers: inline
Type parameters: 'a, 'b

Convert an array to a string using a left and right delimiter and a delimiter between elements. Example: toString_ "[|" "|]" ";" [|1;2;3|] -> "[|1;2;3|]"

left : string
right : string
del : 'a
xs : 'b[]
Returns: string

Type something to start searching.