From ce317d7b3964915c035715deff00b539439588f1 Mon Sep 17 00:00:00 2001 From: Rimu Falko Date: Wed, 22 May 2024 15:32:05 +0200 Subject: [PATCH] Rename iterators to parallel-enumerable, Refactored ReadMe --- ReadMe.md | 51 ++++++++++++++++--- Sources.Build.props | 1 - ...s.cs => EnumerableDisposableExtensions.cs} | 2 +- ...s => FrozenSequence.ParallelEnumerator.cs} | 2 +- .../Collections/FrozenSequence.cs | 2 +- .../Collections/IReadOnlySequence.cs | 2 +- ...> RemovableSequence.ParallelEnumerator.cs} | 3 +- .../Collections/RemovableSequence.cs | 2 +- ...ator.cs => Sequence.ParallelEnumerator.cs} | 3 +- .../Falko.Talkie.Core/Collections/Sequence.cs | 2 +- .../Falko.Talkie.Core/Concurrent/IIterable.cs | 6 --- .../Concurrent/IParallelEnumerable.cs | 6 +++ .../{IIterator.cs => IParallelEnumerator.cs} | 2 +- .../IterablePartitioner.Enumerable.cs | 6 +-- .../Concurrent/IteratorExtensions.cs | 9 ---- ...ons.cs => ParallelEnumerableExtensions.cs} | 6 +-- ...er.cs => ParallelEnumerablePartitioner.cs} | 4 +- ...erator.cs => ParallelEnumeratorAdapter.cs} | 4 +- .../ParallelEnumeratorExtensions.cs | 9 ++++ 19 files changed, 79 insertions(+), 43 deletions(-) rename Sources/Falko.Talkie.Core/Collections/{DisposableSequenceExtensions.cs => EnumerableDisposableExtensions.cs} (82%) rename Sources/Falko.Talkie.Core/Collections/{FrozenSequence.Iterator.cs => FrozenSequence.ParallelEnumerator.cs} (89%) rename Sources/Falko.Talkie.Core/Collections/{RemovableSequence.Iterator.cs => RemovableSequence.ParallelEnumerator.cs} (81%) rename Sources/Falko.Talkie.Core/Collections/{Sequence.Iterator.cs => Sequence.ParallelEnumerator.cs} (81%) delete mode 100644 Sources/Falko.Talkie.Core/Concurrent/IIterable.cs create mode 100644 Sources/Falko.Talkie.Core/Concurrent/IParallelEnumerable.cs rename Sources/Falko.Talkie.Core/Concurrent/{IIterator.cs => IParallelEnumerator.cs} (76%) delete mode 100644 Sources/Falko.Talkie.Core/Concurrent/IteratorExtensions.cs rename Sources/Falko.Talkie.Core/Concurrent/{IterableExtensions.cs => ParallelEnumerableExtensions.cs} (93%) rename Sources/Falko.Talkie.Core/Concurrent/{IterablePartitioner.cs => ParallelEnumerablePartitioner.cs} (63%) rename Sources/Falko.Talkie.Core/Concurrent/{IteratorEnumerator.cs => ParallelEnumeratorAdapter.cs} (58%) create mode 100644 Sources/Falko.Talkie.Core/Concurrent/ParallelEnumeratorExtensions.cs diff --git a/ReadMe.md b/ReadMe.md index b2a25ef..c9fb22e 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -1,17 +1,52 @@ # Talkie -Talkie is a comprehensive framework designed to simplify the development of bots across multiple messengers platforms. +> Talkie is under active development. The underlying C# framework libraries is subject to change. -With its functional interfaces, developers can write code once and deploy it on various platforms -such as Telegram, Discord, and more. +Talkie is a versatile framework designed to streamline the development of bots across various messaging platforms. -The framework is designed with extensibility in mind, -allowing developers to easily add new features and functionalities as needed. +It leverages functional interfaces for messaging cross-platform compatibility, +enabling developers to write code once and deploy it on platforms like Telegram and Discord. + +Whether you're building a simple chatbot or a complex bot, Talkie's lightweight design, native AOT support, and parallel processing capabilities ensure optimal performance. ## Features -- **Unified API**: Write code once and deploy it on multiple platforms. +- **Fast and Lightweight**: Talkie is designed to be fast and lightweight, making it ideal for use in resource-constrained environments or high-traffic, large-scale bots. +- **Native-AOT Support (Latest .NET 8)**: Talkie provides native Ahead-of-Time (AOT) compilation support with the latest .NET 8 framework, enabling developers to compile bots to native code for enhanced performance and memory efficiency. +- **Parallel Processing**: Talkie is optimized to leverage multi-core processors, empowering developers to create bots capable of handling multiple messages concurrently. +- **OOP and Functional Programming**: Talkie offers flexibility by supporting both object-oriented and functional programming paradigms, allowing developers to choose the style that best aligns with their preferences and project requirements. +- **Self-Contained and Independent**: Talkie is self-contained and does not rely on external libraries. This eliminates compatibility concerns, reduces the overall footprint, and simplifies deployment. +- **Cross-Platform Compatibility**: Talkie is engineered for cross-platform compatibility, enabling developers to write code once and deploy it seamlessly across diverse bot platforms, including Telegram, Discord, and more. +- **Extensible Architecture**: Talkie is designed with extensibility in mind, making it easy for developers to add new features, functionalities, and expand platform support as needed. +- **Comprehensive Functionality**: Talkie offers a wide array of features, and managing complex branched code for different bot platforms, all while simplifying code that would be more cumbersome on other platforms. + +## Usage + +### Add the Falko Team NuGet Repository: + +Open your terminal and execute the following command, replacing placeholders with your GitHub credentials: + +```bash +dotnet nuget add source "https://nuget.pkg.github.com/falko-team/index.json" --name falko-team --store-password-in-clear-text --username $YOUR_GITHUB_USERNAME --password $YOUR_GITHUB_ACCESS_TOKEN +``` + +### Install the Talkie Platforms Package: + +If you're using Telegram, install the Talkie Telegram Platform package: + +```bash +dotnet add package Falko.Talkie.Platforms.Telegram +``` + +### Explore the Examples: + +To get started quickly, check out the [Examples](Examples) folder in the Talkie repository +for illustrative code samples and usage demonstrations. + +## License + +This project is licensed under the [BSD 2-Clause License](License.md). -- **Extensible**: Easily add new features and functionalities as needed. +Contributions are welcome! -- **Cross-platform**: Supports multiple messengers platforms such as Telegram, Discord, and more. +**© 2024, Falko Team** diff --git a/Sources.Build.props b/Sources.Build.props index b21e93e..b8d7527 100644 --- a/Sources.Build.props +++ b/Sources.Build.props @@ -4,7 +4,6 @@ true true - true Library diff --git a/Sources/Falko.Talkie.Core/Collections/DisposableSequenceExtensions.cs b/Sources/Falko.Talkie.Core/Collections/EnumerableDisposableExtensions.cs similarity index 82% rename from Sources/Falko.Talkie.Core/Collections/DisposableSequenceExtensions.cs rename to Sources/Falko.Talkie.Core/Collections/EnumerableDisposableExtensions.cs index 6360dc4..5127747 100644 --- a/Sources/Falko.Talkie.Core/Collections/DisposableSequenceExtensions.cs +++ b/Sources/Falko.Talkie.Core/Collections/EnumerableDisposableExtensions.cs @@ -2,7 +2,7 @@ namespace Talkie.Collections; -public static class DisposableSequenceExtensions +public static class EnumerableDisposableExtensions { public static void Add(this IEnumerableDisposable enumerableDisposables, Action dispose) { diff --git a/Sources/Falko.Talkie.Core/Collections/FrozenSequence.Iterator.cs b/Sources/Falko.Talkie.Core/Collections/FrozenSequence.ParallelEnumerator.cs similarity index 89% rename from Sources/Falko.Talkie.Core/Collections/FrozenSequence.Iterator.cs rename to Sources/Falko.Talkie.Core/Collections/FrozenSequence.ParallelEnumerator.cs index 4917d36..8d7c9a6 100644 --- a/Sources/Falko.Talkie.Core/Collections/FrozenSequence.Iterator.cs +++ b/Sources/Falko.Talkie.Core/Collections/FrozenSequence.ParallelEnumerator.cs @@ -8,7 +8,7 @@ namespace Talkie.Collections; public partial class FrozenSequence { [method: MethodImpl(MethodImplOptions.AggressiveInlining)] - private sealed class Iterator(T[] items, int itemsCount) : IIterator + private sealed class ParallelEnumerator(T[] items, int itemsCount) : IParallelEnumerator { private int _lastItemIndex = -1; diff --git a/Sources/Falko.Talkie.Core/Collections/FrozenSequence.cs b/Sources/Falko.Talkie.Core/Collections/FrozenSequence.cs index 47e5acc..31fc2ff 100644 --- a/Sources/Falko.Talkie.Core/Collections/FrozenSequence.cs +++ b/Sources/Falko.Talkie.Core/Collections/FrozenSequence.cs @@ -23,5 +23,5 @@ public FrozenSequence(IEnumerable values) IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); - public IIterator GetIterator() => new Iterator(_items, _itemsCount); + public IParallelEnumerator GetParallelEnumerator() => new ParallelEnumerator(_items, _itemsCount); } diff --git a/Sources/Falko.Talkie.Core/Collections/IReadOnlySequence.cs b/Sources/Falko.Talkie.Core/Collections/IReadOnlySequence.cs index f0cb457..3357aef 100644 --- a/Sources/Falko.Talkie.Core/Collections/IReadOnlySequence.cs +++ b/Sources/Falko.Talkie.Core/Collections/IReadOnlySequence.cs @@ -2,4 +2,4 @@ namespace Talkie.Collections; -public interface IReadOnlySequence : IReadOnlyCollection, IIterable; +public interface IReadOnlySequence : IReadOnlyCollection, IParallelEnumerable; diff --git a/Sources/Falko.Talkie.Core/Collections/RemovableSequence.Iterator.cs b/Sources/Falko.Talkie.Core/Collections/RemovableSequence.ParallelEnumerator.cs similarity index 81% rename from Sources/Falko.Talkie.Core/Collections/RemovableSequence.Iterator.cs rename to Sources/Falko.Talkie.Core/Collections/RemovableSequence.ParallelEnumerator.cs index 07d6196..83e882f 100644 --- a/Sources/Falko.Talkie.Core/Collections/RemovableSequence.Iterator.cs +++ b/Sources/Falko.Talkie.Core/Collections/RemovableSequence.ParallelEnumerator.cs @@ -7,8 +7,9 @@ namespace Talkie.Collections; public partial class RemovableSequence { [method: MethodImpl(MethodImplOptions.AggressiveInlining)] - private sealed class Iterator(Node? first) : IIterator + private sealed class ParallelEnumerator(Node? first) : IParallelEnumerator { + // ReSharper disable once ReplaceWithPrimaryConstructorParameter private Node? _current = first; [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/Sources/Falko.Talkie.Core/Collections/RemovableSequence.cs b/Sources/Falko.Talkie.Core/Collections/RemovableSequence.cs index 0491af3..81445e0 100644 --- a/Sources/Falko.Talkie.Core/Collections/RemovableSequence.cs +++ b/Sources/Falko.Talkie.Core/Collections/RemovableSequence.cs @@ -38,5 +38,5 @@ public Remover Add(T value) IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); - public IIterator GetIterator() => new Iterator(_first); + public IParallelEnumerator GetParallelEnumerator() => new ParallelEnumerator(_first); } diff --git a/Sources/Falko.Talkie.Core/Collections/Sequence.Iterator.cs b/Sources/Falko.Talkie.Core/Collections/Sequence.ParallelEnumerator.cs similarity index 81% rename from Sources/Falko.Talkie.Core/Collections/Sequence.Iterator.cs rename to Sources/Falko.Talkie.Core/Collections/Sequence.ParallelEnumerator.cs index b53d386..eb0334d 100644 --- a/Sources/Falko.Talkie.Core/Collections/Sequence.Iterator.cs +++ b/Sources/Falko.Talkie.Core/Collections/Sequence.ParallelEnumerator.cs @@ -7,8 +7,9 @@ namespace Talkie.Collections; public partial class Sequence { [method: MethodImpl(MethodImplOptions.AggressiveInlining)] - private sealed class Iterator(Node? first) : IIterator + private sealed class ParallelEnumerator(Node? first) : IParallelEnumerator { + // ReSharper disable once ReplaceWithPrimaryConstructorParameter private Node? _current = first; [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/Sources/Falko.Talkie.Core/Collections/Sequence.cs b/Sources/Falko.Talkie.Core/Collections/Sequence.cs index 5058b2d..de87cc4 100644 --- a/Sources/Falko.Talkie.Core/Collections/Sequence.cs +++ b/Sources/Falko.Talkie.Core/Collections/Sequence.cs @@ -35,5 +35,5 @@ public void Add(T value) IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); - public IIterator GetIterator() => new Iterator(_first); + public IParallelEnumerator GetParallelEnumerator() => new ParallelEnumerator(_first); } diff --git a/Sources/Falko.Talkie.Core/Concurrent/IIterable.cs b/Sources/Falko.Talkie.Core/Concurrent/IIterable.cs deleted file mode 100644 index 244b00d..0000000 --- a/Sources/Falko.Talkie.Core/Concurrent/IIterable.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace Talkie.Concurrent; - -public interface IIterable -{ - new IIterator GetIterator(); -} diff --git a/Sources/Falko.Talkie.Core/Concurrent/IParallelEnumerable.cs b/Sources/Falko.Talkie.Core/Concurrent/IParallelEnumerable.cs new file mode 100644 index 0000000..23471b2 --- /dev/null +++ b/Sources/Falko.Talkie.Core/Concurrent/IParallelEnumerable.cs @@ -0,0 +1,6 @@ +namespace Talkie.Concurrent; + +public interface IParallelEnumerable +{ + IParallelEnumerator GetParallelEnumerator(); +} diff --git a/Sources/Falko.Talkie.Core/Concurrent/IIterator.cs b/Sources/Falko.Talkie.Core/Concurrent/IParallelEnumerator.cs similarity index 76% rename from Sources/Falko.Talkie.Core/Concurrent/IIterator.cs rename to Sources/Falko.Talkie.Core/Concurrent/IParallelEnumerator.cs index 6fe3acc..0180ab1 100644 --- a/Sources/Falko.Talkie.Core/Concurrent/IIterator.cs +++ b/Sources/Falko.Talkie.Core/Concurrent/IParallelEnumerator.cs @@ -2,7 +2,7 @@ namespace Talkie.Concurrent; -public interface IIterator +public interface IParallelEnumerator { bool TryMoveNext([MaybeNullWhen(false)] out T item); } diff --git a/Sources/Falko.Talkie.Core/Concurrent/IterablePartitioner.Enumerable.cs b/Sources/Falko.Talkie.Core/Concurrent/IterablePartitioner.Enumerable.cs index 74a69d9..562310e 100644 --- a/Sources/Falko.Talkie.Core/Concurrent/IterablePartitioner.Enumerable.cs +++ b/Sources/Falko.Talkie.Core/Concurrent/IterablePartitioner.Enumerable.cs @@ -2,11 +2,11 @@ namespace Talkie.Concurrent; -internal sealed partial class IterablePartitioner +internal sealed partial class ParallelEnumerablePartitioner { - private sealed class Enumerable(IIterator iterator) : IEnumerable + private sealed class Enumerable(IParallelEnumerator parallelEnumerator) : IEnumerable { - public IEnumerator GetEnumerator() => iterator.ToEnumerable(); + public IEnumerator GetEnumerator() => parallelEnumerator.ToEnumerable(); IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); } diff --git a/Sources/Falko.Talkie.Core/Concurrent/IteratorExtensions.cs b/Sources/Falko.Talkie.Core/Concurrent/IteratorExtensions.cs deleted file mode 100644 index 2321947..0000000 --- a/Sources/Falko.Talkie.Core/Concurrent/IteratorExtensions.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace Talkie.Concurrent; - -public static class IteratorExtensions -{ - public static IEnumerator ToEnumerable(this IIterator iterator) - { - return new IteratorEnumerator(iterator); - } -} diff --git a/Sources/Falko.Talkie.Core/Concurrent/IterableExtensions.cs b/Sources/Falko.Talkie.Core/Concurrent/ParallelEnumerableExtensions.cs similarity index 93% rename from Sources/Falko.Talkie.Core/Concurrent/IterableExtensions.cs rename to Sources/Falko.Talkie.Core/Concurrent/ParallelEnumerableExtensions.cs index 90166f8..284a377 100644 --- a/Sources/Falko.Talkie.Core/Concurrent/IterableExtensions.cs +++ b/Sources/Falko.Talkie.Core/Concurrent/ParallelEnumerableExtensions.cs @@ -3,11 +3,11 @@ namespace Talkie.Concurrent; -public static class IterableExtensions +public static class ParallelEnumerableExtensions { - public static Partitioner ToPartitioner(this IIterable iterable) + public static Partitioner ToPartitioner(this IParallelEnumerable parallelEnumerable) { - return new IterablePartitioner(iterable); + return new ParallelEnumerablePartitioner(parallelEnumerable); } public static SequenceParallelismCoordinator.Static Parallelize(this IReadOnlySequence sequence) diff --git a/Sources/Falko.Talkie.Core/Concurrent/IterablePartitioner.cs b/Sources/Falko.Talkie.Core/Concurrent/ParallelEnumerablePartitioner.cs similarity index 63% rename from Sources/Falko.Talkie.Core/Concurrent/IterablePartitioner.cs rename to Sources/Falko.Talkie.Core/Concurrent/ParallelEnumerablePartitioner.cs index 6ef6107..cba7447 100644 --- a/Sources/Falko.Talkie.Core/Concurrent/IterablePartitioner.cs +++ b/Sources/Falko.Talkie.Core/Concurrent/ParallelEnumerablePartitioner.cs @@ -2,11 +2,11 @@ namespace Talkie.Concurrent; -internal sealed partial class IterablePartitioner(IIterable iterable) : Partitioner +internal sealed partial class ParallelEnumerablePartitioner(IParallelEnumerable parallelEnumerable) : Partitioner { public override bool SupportsDynamicPartitions => true; public override IList> GetPartitions(int partitionCount) => throw new NotSupportedException(); - public override IEnumerable GetDynamicPartitions() => new Enumerable(iterable.GetIterator()); + public override IEnumerable GetDynamicPartitions() => new Enumerable(parallelEnumerable.GetParallelEnumerator()); } diff --git a/Sources/Falko.Talkie.Core/Concurrent/IteratorEnumerator.cs b/Sources/Falko.Talkie.Core/Concurrent/ParallelEnumeratorAdapter.cs similarity index 58% rename from Sources/Falko.Talkie.Core/Concurrent/IteratorEnumerator.cs rename to Sources/Falko.Talkie.Core/Concurrent/ParallelEnumeratorAdapter.cs index dcce3f4..1c3bd10 100644 --- a/Sources/Falko.Talkie.Core/Concurrent/IteratorEnumerator.cs +++ b/Sources/Falko.Talkie.Core/Concurrent/ParallelEnumeratorAdapter.cs @@ -2,7 +2,7 @@ namespace Talkie.Concurrent; -internal sealed class IteratorEnumerator(IIterator iterator) : IEnumerator +internal sealed class ParallelEnumeratorAdapter(IParallelEnumerator parallelEnumerator) : IEnumerator { private T? _current; @@ -10,7 +10,7 @@ internal sealed class IteratorEnumerator(IIterator iterator) : IEnumerator object IEnumerator.Current => _current!; - public bool MoveNext() => iterator.TryMoveNext(out _current); + public bool MoveNext() => parallelEnumerator.TryMoveNext(out _current); public void Reset() => throw new NotSupportedException(); diff --git a/Sources/Falko.Talkie.Core/Concurrent/ParallelEnumeratorExtensions.cs b/Sources/Falko.Talkie.Core/Concurrent/ParallelEnumeratorExtensions.cs new file mode 100644 index 0000000..ec6c1c5 --- /dev/null +++ b/Sources/Falko.Talkie.Core/Concurrent/ParallelEnumeratorExtensions.cs @@ -0,0 +1,9 @@ +namespace Talkie.Concurrent; + +public static class ParallelEnumeratorExtensions +{ + public static IEnumerator ToEnumerable(this IParallelEnumerator parallelEnumerator) + { + return new ParallelEnumeratorAdapter(parallelEnumerator); + } +}