https://github.com/goswinr/arrayt
Extensions for Array<'T> in F#
https://github.com/goswinr/arrayt
array fable fsharp library
Last synced: 5 days ago
JSON representation
Extensions for Array<'T> in F#
- Host: GitHub
- URL: https://github.com/goswinr/arrayt
- Owner: goswinr
- License: mit
- Created: 2024-02-25T20:04:13.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-06-09T15:37:16.000Z (about 1 month ago)
- Last Synced: 2025-06-14T22:48:00.131Z (about 1 month ago)
- Topics: array, fable, fsharp, library
- Language: F#
- Homepage: https://goswinr.github.io/ArrayT/
- Size: 189 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README

# ArrayT[](https://www.nuget.org/packages/ArrayT/)
[](https://github.com/goswinr/ArrayT/actions/workflows/build.yml)
[](https://github.com/goswinr/ArrayT/actions/workflows/docs.yml)
[](https://github.com/goswinr/ArrayT/actions/workflows/test.yml)
[](https://github.com/goswinr/ArrayT/actions/workflows/outdatedDotnetTool.yml)
[](LICENSE.md)
ArrayT is an F# extension and module library for `Array<'T>`
It also works in Javascript and Typescript with [Fable](https://fable.io/).
### 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:
- An `Array` module that has a additional functions to the `Array` module from [`FSharp.Core`](https://fsharp.github.io/fsharp-core-docs/reference/fsharp-collections-arraymodule.html).
See [docs](https://goswinr.github.io/ArrayT/reference/arrayt-array.html)- Extension members on `Array` like
`.Get(idx)` `.Set(idx,item)` `.First` `.Last` `.SecondLast` `xs.DebugIdx.[i]` and more..
With nicer IndexOutOfRangeExceptions that include the bad index and the actual size.
See [docs](https://goswinr.github.io/ArrayT/reference/arrayt-autoopenarraytextensions.html)### Usage
Just open the namespace```fsharp
open ArrayT
```
this namespace contains:- a module also called `Array`. It will add additional functions to the `Array` module from `FSharp.Core`.
- this will also auto open the extension members on `Array<'T>`
### Example
```fsharp
#r "nuget: ArrayT"
open ArrayTlet xs = [| 0 .. 88 |]
xs.Get(99)
```
throws```
System.IndexOutOfRangeException: Array.Get: Can't get index 99 from:
array 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](https://goswinr.github.io/ArrayT/reference/arrayt.html)
### Tests
All Tests run in both javascript and dotnet.
Successful Fable compilation to typescript is verified too.
Go to the tests folder:```bash
cd Tests
```For testing with .NET using Expecto:
```bash
dotnet run
```for JS testing with Fable.Mocha and TS verification:
```bash
npm test
```### License
[MIT](https://github.com/goswinr/ArrayT/blob/main/LICENSE.md)### Changelog
see [CHANGELOG.md](https://github.com/goswinr/ArrayT/blob/main/CHANGELOG.md)