ResizeArrayT 0.26.0

dotnet add package ResizeArrayT --version 0.26.0
                    
NuGet\Install-Package ResizeArrayT -Version 0.26.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ResizeArrayT" Version="0.26.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ResizeArrayT" Version="0.26.0" />
                    
Directory.Packages.props
<PackageReference Include="ResizeArrayT" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add ResizeArrayT --version 0.26.0
                    
#r "nuget: ResizeArrayT, 0.26.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package ResizeArrayT@0.26.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=ResizeArrayT&version=0.26.0
                    
Install as a Cake Addin
#tool nuget:?package=ResizeArrayT&version=0.26.0
                    
Install as a Cake Tool

Logo

ResizeArrayT

ResizeArrayT on nuget.org Build Status Docs Build Status Test Status license code size

ResizeArrayT is an F# extension and module library for ResizeArray<'T> ( = Collection.Generic.List<'T>).
It provides all the functions from the Array module in FSharp.Core for ResizeArray.
And more.

It also works in Javascript and Typescript with Fable.

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

I was always annoyed that an IndexOutOfRangeException does not include the actual bad index nor the actual size of the array.
This library fixes that in the resizeArray.Get, resizeArray.Set, resizeArray.Slice and similar instance methods for item access.
I made a similar a similar library for array<'T>: https://github.com/goswinr/ArrayT/ .

Why ?

Yes, F#'s array and list modules can do these kind of operations on collections too.
But ResizeArray, being mutable, still offers the best performance for collections that can expand & shrink and need random access via an index.
In fact FSharp.Core uses a very similar module internally.

It Includes:

  • A ResizeArray module that has all functions from Array module from FSharp.Core reimplemented.
    Including the sub module for Parallel computing.

  • A Computational Expressions resizeArray that can be used like existing ones for seq.

  • Support for F# slicing operator and indexing from the end. e.g: items.[ 1 .. ^1].

  • Extension members on ResizeArray like .Get .Set .First .Last .SecondLast and more.
    With nicer IndexOutOfRangeExceptions that include the bad index and the actual size.

  • All Tests from the from FSharp.Core's Array module ported and adapted to run in both javascript and dotnet.

Namespace

The main namespace is ResizeArrayT.
It was renamed from ResizeArray to ResizeArrayT in release 0.23. When used in scripting this helps avoid name collisions with the
module inside of the same name. Reference Issue

Older versions of the library will still work with the old namespace ResizeArray.
And can be found on nuget.org with the name ResizeArray.

Usage

Just open the namespace

open ResizeArrayT

this namespace contains:

  • a module also called ResizeArray
  • a Computational Expressions called resizeArray
  • this will also auto open the extension members on ResizeArray<'T>

then you can do:

let evenNumbers =
    resizeArray {  // a Computational Expression like seq
        for i = 0 to 99 do
            if i % 2 = 0 then
                i
    }

let oddNumbers = evenNumbers |> ResizeArray.map (fun x -> x + 1) // ResizeArray module

let hundred = oddNumbers.Last // Extension member to access the last item in the list

Computational Expression

The resizeArray { ... } builder supports for, while, yield, yield!, try/with, try/finally, and use:

// Yield individual items and sequences
let mixed =
    resizeArray {
        1
        2
        yield! [3; 4; 5]   // yield from any seq
        for i in 6..10 do
            i
    }

// Filter inside the builder
let primes =
    resizeArray {
        for n = 2 to 50 do
            let mutable isPrime = true
            for d = 2 to int (sqrt (float n)) do
                if n % d = 0 then isPrime <- false
            if isPrime then n
    }

Extension Members

Access items with descriptive error messages that include the bad index and the collection size:

let items = ResizeArray([| "a"; "b"; "c"; "d"; "e" |])

items.First        // "a"
items.Second       // "b"
items.Last         // "e"
items.SecondLast   // "d"
items.LastIndex    // 4

// Negative indexing (Python-style: -1 is last item)
items.GetNeg(-1)   // "e"
items.GetNeg(-2)   // "d"

// Looped indexing (wraps around)
items.GetLooped(7) // "c"  (index 7 wraps to index 2)

// Status checks
items.IsEmpty      // false
items.IsNotEmpty   // true
items.HasItems     // true
items.IsSingleton  // false

Slicing

F# slicing notation is fully supported, including indexing from the end with ^:

let nums = ResizeArray([| 10; 20; 30; 40; 50 |])

nums.[1..3]        // ResizeArray [20; 30; 40]
nums.[..2]         // ResizeArray [10; 20; 30]
nums.[2..]         // ResizeArray [30; 40; 50]
nums.[1..^1]       // ResizeArray [20; 30; 40]  (from index 1 to second-last)
nums.[^0]          // 50  (last item)

Pop, Clone, and InsertAtStart

let xs = ResizeArray([| 1; 2; 3; 4; 5 |])

let last = xs.Pop()            // returns 5, xs is now [1; 2; 3; 4]
let second = xs.Pop(1)         // returns 2, xs is now [1; 3; 4]

xs.InsertAtStart(0)            // xs is now [0; 1; 3; 4]

let copy = xs.Clone()          // shallow copy

ResizeArray Module

All functions from FSharp.Core's Array module are available, plus many extras:

// Standard functional operations
let doubled = items |> ResizeArray.map (fun x -> x * 2)
let evens   = items |> ResizeArray.filter (fun x -> x % 2 = 0)
let total   = items |> ResizeArray.sum

// Positional access
let first     = items |> ResizeArray.first
let last      = items |> ResizeArray.last
let secLast   = items |> ResizeArray.secondLast

// Grouping and counting
let grouped  = items |> ResizeArray.groupBy (fun x -> x % 3)
let counts   = items |> ResizeArray.countBy (fun x -> x % 3)

// Finding duplicates
let dupes    = items |> ResizeArray.duplicates
let dupesBy  = items |> ResizeArray.duplicatesBy (fun x -> x % 10)

// Partitioning into multiple groups
let trueOnes, falseOnes = items |> ResizeArray.partition (fun x -> x > 3)

let small, medium, large =
    items |> ResizeArray.partition3
        (fun x -> x < 10)
        (fun x -> x < 50)

// Windowed iteration (useful for geometry/polyline processing)
items |> ResizeArray.windowed2 |> Seq.iter (fun (a, b) -> printfn "%A -> %A" a b)
items |> ResizeArray.prevThisNext |> Seq.iter (fun (prev, this', next) -> printfn "%A %A %A" prev this' next)

Construction and Conversion

let empty  = ResizeArray.empty<int>
let single = ResizeArray.singleton 42
let filled = ResizeArray.create 10 0         // 10 zeros
let inited = ResizeArray.init 5 (fun i -> i * i) // [0; 1; 4; 9; 16]

// From other collections
let fromList  = ResizeArray.ofList [1; 2; 3]
let fromArray = ResizeArray.ofArray [|1; 2; 3|]
let fromSeq   = ResizeArray.ofSeq (seq { 1..10 })

// To other collections
let asArray = items |> ResizeArray.toArray
let asList  = items |> ResizeArray.toList
let asSeq   = items |> ResizeArray.toSeq

Error Messages

When an index is out of range, you get a descriptive exception including the bad index and the collection content:

System.IndexOutOfRangeException:
ResizeArray.Get: Can't get index 5 from:
ResizeArray<String> with 3 items:
  0: "a"
  1: "b"
  2: "c"

Operators

Open the Operators module to combine collections with ++ and +++:

open ResizeArrayT.Operators

let combined = xs ++ ys         // from two ICollection<'T>, preallocates capacity
let combined' = xs +++ ys       // from two seq<'T>

Parallel

A sub module for parallel operations (on .NET only):

let results = items |> ResizeArray.Parallel.map (fun x -> expensiveComputation x)
let chosen  = items |> ResizeArray.Parallel.choose (fun x -> tryProcess x)

Use of AI and LLMs

All core function are are written by hand to ensure performance and correctness.
However, AI tools have been used for code review, typo and grammar checking in documentation
and to generate not all but many of the tests.

Full API Documentation

goswinr.github.io/ResizeArrayT

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

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Framework net472 is compatible.  net48 was computed.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.26.0 140 3/13/2026
0.25.0 529 10/11/2025
0.24.0 136 10/11/2025
0.23.0 329 5/24/2025

### Changed

- allow ResizeArray.asArray only on reference types