An open API service indexing awesome lists of open source software.

https://github.com/cdiggins/plato.collections

A library of immutable abstract data types inspired by LINQ.
https://github.com/cdiggins/plato.collections

Last synced: 8 months ago
JSON representation

A library of immutable abstract data types inspired by LINQ.

Awesome Lists containing this project

README

          

# Plato.Collections

A library of immutable abstract data types inspired by LINQ.
Plato.Collections is built in Platonic C# and is fully compatible with .NET Standard 2.0.

## Platonic C#

Platonic C# is a set of coding guidelines for using C# that enable data structures and algorithms to be machine translated into the Plato language.
Plato is being developed as a high-performance pure functional language that can target multiple platforms.

## Design Principles

Plato.Collections is designed starting from simple generic immutable interfaces, with a rich library extension methods, and factory functions.

1. All collections are immutable, side-effect free, and thread-safe.
1. Simplicity is chosen over performance
1. Required API for an Interfaces should each be as small as possible
1. Each interface should describe a single well-defined concept
1. Data types with different algorithmic complexity need different representations
1. Low-level performance concerns beyond should be primarily the concern of optimization tools

## ISequence versis IEnumerable

The `System.IEnumerable` interface represents a potentially mutable type and has the following interfaces:

```csharp
interface IEnumerable
{
IEnumerator GetEnumerator();
}
```

The `Plato.ISequence` type is quite similar, but only represents immutable types. One of the advantages
of an `ISequence` is that it can safely be enumerated multiple times, and has a hard guarantee of never
changing under.

```csharp
interface ISequence
{
IIterator Iterator { get; }
}
```

The `IIterator` type returned from the `Iterator` property, is also an immutable type unlike `IEnumerable`.
This affords several advantages such as the fact that a collection of iterators can be safely made representing different
locations in a sequence.

## IIterator versus IEnumerator

The `System.IEnumerator` interface represents a mutable type and has the following interfaces:

```csharp
interface IEnumerator
{
T Current { get; }
bool MoveNext();
void Reset();
void Dispose();
}
```

The comparable interface `Plato.IIterator` on the other hand is immutable and has the following interface:

```csharp
interface IIterator
{
T Value { get; }
bool HasValue { get; }
IIterator Next { get; }
}
```

Notice that `IIterator` cannot be disposed, nor can it be reset. Unlike the `IEnumerator`
it is initialized to point to the first element in a sequence, as opposed to pointing to a location before the
first spot (`IEnumerator` requires an initial call to `MoveNext()` before values can be retrieved).

## IArray vs LINQ on Array

The `Plato.IArray` interface provides a read-only interface to arrays.
Unlike `Plato.ISequence` or `System.IEnumerable`, many of the `IArray` operations
return an `IArray`, which retains algorithmic complexity O(1) for
querying the count, or random access of elements.

```csharp
interface IArray
{
int Count { get; }
this[int n] { get; }
}
```

The `IArray` implementation is based on the [LinqArray](https://github.com/vimaec/LinqArray) library, which in turn
is based on article at CodeProject.com called [LINQ for Immutable Arrays](https://www.codeproject.com/Articles/517728/LINQ-for-Immutable-Arrays).

## Additional Data Types

Some of the additional types provided by Plato.Collections library includes:

* `ICountedSequence`
* `ISet`
* `IQueue`
* `IDequeue`
* `IStack`
* `IHeap`
* `IDictionary`
* `IMultiDictionary`
* `IBiDictionary`