Header menu logo ArrayT

Logo

ArrayT

ArrayT on nuget.org Build Status Docs Build Status Test Status Check dotnet tools license code size

ArrayT is an F# extension and module library for Array<'T>

It also works in Javascript and Typescript with Fable.

Motivation

I was always annoyed that an IndexOutOfRangeException does not include the actual index that was out of bounds nor the actual size of the array. This library fixes that in array.Get, array.Set, array.Slice and other item access functions.

This library was designed for use with F# scripting.
Functions and methods never return null.
Only functions starting with try... will return an F# Option.
Otherwise when a function fails on invalid input it will throw a descriptive exception.

See also https://github.com/goswinr/ResizeArray/ for a similar library for ResizeArray<'T>.

It Includes:

Usage

Just open the namespace

open ArrayT

this namespace contains:

Example

#r "nuget: ArrayT"
open ArrayT

let xs = [| 0 .. 88 |]

xs.Get(99)

throws

System.IndexOutOfRangeException: Array.Get: Can't get index 99 from:
array<Int32> with 89 items:
  0: 0
  1: 1
  2: 2
  3: 3
  4: 4
  ...
  88: 88

instead of the usual

System.IndexOutOfRangeException: Index was outside the bounds of the array.

If you want to use the index notation xs.[i] instead of the Get method you can use the DebugIdx member

xs.DebugIdx.[i]

Full API Documentation

goswinr.github.io/ArrayT

Tests

All Tests run in both javascript and dotnet. Successful Fable compilation to typescript is verified too. Go to the tests folder:

cd Tests

For testing with .NET using Expecto:

dotnet run

for JS testing with Fable.Mocha and TS verification:

npm test

License

MIT

Changelog

see CHANGELOG.md

namespace ArrayT
val xs: int array
member array.Get: index: int -> 'T
namespace System
Multiple items
type IndexOutOfRangeException = inherit SystemException new: unit -> unit + 2 overloads
<summary>The exception that is thrown when an attempt is made to access an element of an array or collection with an index that is outside its bounds.</summary>

--------------------
System.IndexOutOfRangeException() : System.IndexOutOfRangeException
System.IndexOutOfRangeException(message: string) : System.IndexOutOfRangeException
System.IndexOutOfRangeException(message: string, innerException: exn) : System.IndexOutOfRangeException
Multiple items
module Array from ArrayT
<summary> The main module for functions on Array&lt;'T&gt;. This module provides additional functions to ones from FSharp.Core.Array module. </summary>

--------------------
module Array from Microsoft.FSharp.Collections
type 'T array = 'T array

Type something to start searching.