https://github.com/vimaec/linqarray.dart
Dart implementation of LinqArray
https://github.com/vimaec/linqarray.dart
Last synced: about 1 month ago
JSON representation
Dart implementation of LinqArray
- Host: GitHub
- URL: https://github.com/vimaec/linqarray.dart
- Owner: vimaec
- License: mit
- Created: 2022-08-02T12:56:12.000Z (almost 4 years ago)
- Default Branch: develop
- Last Pushed: 2022-08-02T13:20:34.000Z (almost 4 years ago)
- Last Synced: 2025-01-09T07:09:15.053Z (over 1 year ago)
- Language: Dart
- Size: 13.7 KB
- Stars: 0
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# LinqArray
**LinqArray** is a pure functional .NET library from **[Ara 3D](https://ara3d.com)** that provides LINQ functionality for
immutable (read only) arrays, rather than streams, while preserving `O(1)` complexity when retrieving the count or items by index.
It is performant, memory efficient, cross-platform, safe, and easy to use.
## Overview
LinqArray is a set of extension methods build on the `System.IReadonlyList` interface which effectively is:
```
interface IReadonlyList {
int Count { get; }
T this[int n] { get; }
}
```
Because the interface does not mutate objects it is safe to use in a multithreaded context. Furthermore, as with regular LINQ for `IEnumerable`,
evaluation of many of the operations can be performed on demand (aka lazily).
## Motivation
There are two key characteristics of an array data type which are important to maintain in some problem domains:
1. Retrieving size of collection in `O(1)`
2. Retrieving any item in collection by index in `O(1)`
LINQ provides a large library of extremely useful and powerful algorithms that work on any data type that can be enumerated.
However most LINQ methods return an `IEnumerable` interface which has `O(N)` time for retrieving the size of a collection, or `O(N)` time
for retrieving an element in the collection at a given index.
### Note about Big O Complexity
The notation `O(1)` is called Big-O notation and describes the average running time of an operation in terms of the size of the input set.
The `O(1)` means that the running time of the operation is a fixed constant independent of the size of the collection.
### Why use Interfaces versus Types
Using concrete types like `List` or `Array` versus an interface leadas to code that is more verbose and harder to maintain because it
commit library authors and consumers to uses a specific implementation of an abstract data type. Library functions then have to be written
for each type. This is why interfaces like `IEnumerable` are so prevalent: using extension methods we can easily write libraries that work
on any conforming type. The closest thing to an array
## Extension Methods
LinqArray provides many of the same extension methods for `IReadOnlyList` as LINQ does for objects implementing the `IEnumerable` interface. Some examples include:
* `Aggregate`
* `Select`
* `Zip`
* `Take`
* `Skip`
* `Reverse`
* `All`
* `Any`
* `Count`
## Status
The project is under heavy development but the core functionality is fixed.
## Similar Work
This library is based on an article on CodeProject.com called [LINQ for Immutable Arrays](https://www.codeproject.com/Articles/517728/LINQ-for-Immutable-Arrays). While I worked at Autodesk we used a library based on this article in Autodesk 3ds Max 2016 and later, which shows that
Unlike [LinqFaster](https://github.com/jackmott/LinqFaster) by Jack Mott evaluations of functions happen lazily, and have no side effects. This means that this library can be easily used in a multi-threaded context without inccurring the overhead and complexity of synchronization.