https://github.com/jacksondunstan/iterator
Iterator Library for C# and Unity
https://github.com/jacksondunstan/iterator
Last synced: 21 days ago
JSON representation
Iterator Library for C# and Unity
- Host: GitHub
- URL: https://github.com/jacksondunstan/iterator
- Owner: jacksondunstan
- License: mit
- Created: 2016-06-13T06:44:40.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2021-03-27T18:26:40.000Z (about 4 years ago)
- Last Synced: 2025-03-26T03:02:34.307Z (about 1 month ago)
- Language: C#
- Homepage: https://jacksondunstan.com/articles/3471
- Size: 36.1 KB
- Stars: 180
- Watchers: 10
- Forks: 15
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# About
* A no-GC version of C#'s `IEnumerator` and LINQ
* Inspired by C++'s `` and `` headers
* Useful for any C# project with additional support for Unity# Getting Started
## Unity Projects
Clone or download this repository and copy the `JacksonDunstanIterator` directory somewhere inside your Unity project's `Assets` directory.
## Non-Unity Projects
Clone or download this repository and add all the `.cs` files directly under the `JacksonDunstanIterator` directory to your C# project.
# Usage
There are three iterator types:
* `ArrayIterator` for managed arrays (`T[]`)
* `ListIterator` for `List`
* `NativeArrayIterator` for `NativeArray` (automatically compiled out when Unity 2018.1+ isn't available)They all have the same API. Here's the basics of using `ArrayIterator`:
```csharp
// Get an array
int[] array = new [] { 30, 10, 20, 40 };// Get an iterator to the beginning of the array
ArrayIterator begin = array.Begin();// Get the value of the iterator
int val = begin.GetCurrent();// Move to the next element
ArrayIterator second = begin.GetNext();// Get an iterator to one past the end of the array
ArrayIterator end = array.End();// Reverse [ 10, 20, 40] so the array is [ 30, 40, 20, 10 ]
second.Reverse(end);// Search for an element satisfying a condition
ArrayIterator it20 = begin.FindIf(end, e => e < 25);
```There is much more functionality available. See [the source](JacksonDunstanIterator/ArrayIterator.cs) for more.
To read about the making of this library, see the _Enumerables Without the Garbage_ series:
* [Part 1](https://jacksondunstan.com/articles/3471)
* [Part 2](https://jacksondunstan.com/articles/3482)
* [Part 3](https://jacksondunstan.com/articles/3491)
* [Part 4](https://jacksondunstan.com/articles/3508)
* [Part 5](https://jacksondunstan.com/articles/3515)
* [Part 6](https://jacksondunstan.com/articles/3524)
* [Part 7](https://jacksondunstan.com/articles/3541)
* [Part 8](https://jacksondunstan.com/articles/4905)# License
[MIT](LICENSE.txt)