Code Monkey home page Code Monkey logo

superlinq's Introduction

๐Ÿ‘‹ Hello, folks!

โœ Blog & Writing

I am working on rebuilding my blog here on GitHub.

๐Ÿ”ง Technologies & Tools

๐Ÿ“ˆ GitHub Stats

viceroypenguin's GitHub Stats Metrics

superlinq's People

Contributors

ambientlion avatar anders9ustafsson avatar angularsen avatar arithmomaniac avatar atifaziz avatar bouke avatar dependabot[bot] avatar dferretti avatar elianora avatar fsateler avatar head0nf1re avatar johannesrudolph avatar jskeet avatar julianlettner avatar julienasp avatar klmr avatar leandromoh avatar methuselah96 avatar miffyliye avatar nstuller avatar ojraqueno avatar orace avatar sholland1 avatar sid-6581 avatar tcortega avatar tg73 avatar viceroypenguin avatar vladimirrybalko avatar weihanli avatar yln avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

superlinq's Issues

.Replace() operator

public static IEnumerable<TSource> Replace<TSource>(this IEnumerable<TSource> source, Index index, TSource value);

Used to replace a single item at a specific index while streaming a sequence.

Improve Join functions

  • Add .LoopJoin() [Inner, Left outer, Cross Apply, Outer Apply] This is just .Select()/.SelectMany()
  • Add .HashJoin() [Inner, Left outer, Right outer, Full outer] .Join()/.GroupJoin() uses hash join - just need to clean up .LeftJoin()/.RightJoin(); maybe improve .FullJoin()
  • Add .MergeJoin() [Inner, Left outer, Right outer, Full outer]
  • Update existing methods (.FullJoin(), OrderedMerge(), etc.) as implementations of above

Debate: Add .LoopJoin() and .HashJoin() as aliases to .Select() and .Join(), for completeness/equivalence to .MergeJoin()?

MaxElementsBy removal

I updated to the latest package and see MaxElementsBy has been removed. In the doc I see that the recommended method to use instead is PartialSortBy but no example is provided.

I want to return all of the items that share the maximum count (there can be more than one and I don't want to set a limit). So before I had code like:

var maxItems = items.MaxElementsBy(item => item.Value);

So now it looks like the code should be like the following to achieve the same results:

var maxItems = items.PartialSortBy(int.MaxValue, (item) => item.Value);

I switched to this package from MoreLinq as I agree with the idea of deprecating Linq methods that the common library adds. But in this case the base method has different functionality (MaxBy only returns one item). PartialSortBy with int.MaxValue was not intuitive to figure out but if it works the same I guess I will use it

Equivalent support for IAsyncEnumerable

For each current method, add an equivalent method for IAsyncEnumerables.

Progress:

  • Acquire
  • Aggregate
  • AggregateRight
  • AtLeast
  • AtMost
  • Backsert
  • Batch
  • Cartesian
  • Choose
  • CompareCount
  • Consume
  • CountBetween
  • CountBy
  • CountDown
  • DenseRank
  • DenseRankBy
  • DistinctBy
  • ElementAt (pre-.NET 6)
  • EndsWith
  • Exactly
  • ExceptBy
  • Exclude (#10)
  • FallbackIfEmpty
  • FillBackward
  • FillForward
  • Flatten
  • Fold
  • From
  • FullGroupJoin (#19)
  • FullJoin (#19)
  • Generate
  • GenerateByIndex
  • GroupAdjacent
  • Index
  • IndexBy
  • Insert
  • Interleave
  • Lag
  • Lead
  • LeftJoin (#19)
  • Move (#27)
  • OrderBy
  • OrderedMerge (#19)
  • Pad
  • PadStart
  • PartialSort
  • PartialSortBy
  • Partition
  • Permutations (#20)
  • Pipe
  • PreScan
  • Random
  • RandomDouble
  • RandomSubset (#20)
  • Rank (#13)
  • RankBy (#13)
  • Return
  • RightJoin (#19)
  • RunLengthEncode
  • ScanBy
  • ScanRight
  • Segment
  • Sequence
  • Shuffle (#20)
  • SkipUntil
  • Slice
  • SortedMerge
  • Split
  • StartsWith
  • Subsets (#20)
  • TagFirstLast
  • Take (pre-.NET 6)
  • TakeEvery
  • TakeUntil
  • ThenBy
  • ToArrayByIndex
  • ToDataTable
  • ToDelimitedString
  • ToDictionary
  • ToLookup
  • Transpose
  • TraverseBreadthFirst (#21)
  • TraverseDepthFirst (#21)
  • Trace
  • TrySingle
  • Unfold
  • Window
  • WindowLeft
  • WindowRight
  • ZipLongest
  • ZipShortest

Some methods missing explanations for why not implemented in async

For example:

SuperLinq/README.md

Lines 141 to 146 in f52cca2

| ToDataTable | โœ”๏ธ | โŒ |
| ToDelimitedString | โœ”๏ธ | โŒ |
| ToDictionary | โœ”๏ธ | โŒ |
| ToLookup | โœ”๏ธ | โŒ |
| Trace | โœ”๏ธ | โŒ |
| Transpose | โœ”๏ธ | โŒ |

These methods are not listed as obsolete in the sync versions; should there be backlog items for them?

Reduced Allocation `Batch` and `Window`

Figure out a way to add a reduced (or zero) -allocation version of Batch and Window (and other buffer calls). Possibly by receiving an array or by allocating only a single array and passing it as a ReadOnlySpan<> to a projection method.

  • Window (#134)
  • WindowLeft (#136)
  • WindowRight (#135)
  • Batch (#197)
  • Permutations
  • Subsets (??)

Add `List<T>` item finding methods

List<T> has some useful finding methods that should be implemented for IEnumerable<T>

  • IndexOf<T>(this IEnumerable<T> source, T value[, Index index])
  • LastIndex<T>(this IEnumerable<T> source, T value[, Index index])
  • FindIndex<T>(this IEnumerable<T> source, [Index index,] Func<T, bool> predicate)
  • FindLastIndex<T>(this IEnumerable<T> source, [Index index,] Func<T, bool> predicate)
  • Update (Last)IndexOf to proxy to Find(Last)Index

`TestingSequence`

A review of all current unit tests should be taken to confirm that TestingSequence is being used everywhere.

Possible error in `GetShortestPath`

I was using GetShortestPath for a certain online Christmas challenge, but it was returning unstable results. After switching to QuikGraph, my code worked great. Either I am using GetShortestPath wrong, or it has a bug. Could you help looking into it?

Here is an xUnit test demonstrating the error. It constructs a graph, shuffles the outgoing nodes, and computes the shortest distance from AA to UM. It can easily be seen that going through QT, the shortest distance is 3. However, it yields distances such as 6, 9 and 14 (and also 3).

using QuikGraph;
using QuikGraph.Algorithms;
using SuperLinq;
using Xunit;

namespace AdventOfCode.Tests;

public class GraphTests
{
    class Valve
    {
        public string Name { get; init; }
        public Valve[] Next { get; set; }
    }

    [Fact]
    public void Test()
    {
        var data = """
            EJ => MC
            WC => OW, RU
            NP => VR, KL
            AA => QT, AP, EZ, AK, XV
            VO => KM, RF, HS, LJ, IA
            CB => UI, UP
            TE => JT
            CZ => UP, OW
            LJ => DV, VO
            UP => SK, CB, CZ
            FP => OW, RE
            KM => SE, VO
            DV => LJ, UM
            FL => AH, TS
            VR => DM, TF, NP
            IA => VS, VO
            RF => VO, JF
            RT => UM, SE
            RU => AR, WC
            SE => GU, KM, CX, RT
            MC => EJ, AR
            TF => AH, VR
            CX => SE, TO
            GL => UY, KL, CY
            GU => SE, EZ
            VS => XN, IA
            EZ => AA, GU
            GK => FI, HZ
            JT => TE, XN
            DM => VR, HZ
            AR => UI, RU, MC
            XN => XP, JT, VS, GT, CY
            CY => XN, GL
            QT => UM, AA
            KL => GL, NP
            SK => XV, UP
            OW => CZ, WC, FP
            AK => AA, HS
            XV => AA, SK
            GT => XN, UM
            FI => JF, GK
            UY => JF, GL
            UM => DV, GT, RT, QT
            IQ => HZ, AH
            JF => RF, FI, UY, RE, TS
            TS => JF, FL
            AH => IQ, FL, TF
            HS => AK, VO
            HZ => IQ, DM, GK
            TO => CX
            XP => AP, XN
            AP => XP, AA
            RE => JF, FP
            UI => AR, CB
            """;

        var lines = data.Trim().Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
        var nodes = new Dictionary<string, Valve>();

        // Create vertices
        foreach (var line in lines)
        {
            var name = line.Split(" => ")[0];
            nodes.Add(name, new Valve { Name = name });
        }

        // Create edges
        foreach (var line in lines)
        {
            var name = line.Split(" => ")[0];
            var outNodesNames = line.Split(" => ")[1].Split(", ");
            var outNodes = outNodesNames.Select(outName => nodes[outName]).ToArray();
            nodes[name].Next = outNodes;
        }

        // Compute shortest path a few times
        for (var i = 0; i < 1000; i++)
        {
            foreach (var node in nodes.Values)
            {
                node.Next = node.Next.RandomSubset(node.Next.Length).ToArray();
            }

            // Expect AA -> QT -> UM
            Assert.Equal(3, SuperEnumerable.GetShortestPath<Valve, int>(
                nodes["AA"], 
                (v, c) => v.Next.Select(n => (n, 1)),
                nodes["UM"]
            ).Count());
        }
    }
}

Restore `EquiZip`

EquiZip was removed as being redundant to Enumerable.Zip; however, Enumerable.Zip has behavior matching ZipShortest, not EquiZip. EquiZip should be restored as an operator.

ZipShortest should be reviewed further as an independent operator or proxy function for corelib Enumerable.Zip

ToArray() and ToList() with length

I created a PR (#70) about simple overload for ToArray() and ToList() with lenght parameter. With lenght we can avoid multiple creations of array/list when rewriting IEnumerable to these collections.

Add `GetShortestPath` overload

It would be nice to have another overload of GetShortestPath/GetShortestPathCost that receives a Func<TState, bool> predicate instead of a TState end for identifying the end position.

Reliance on https://github.com/dotnet/reactive - is this good? is this temporary?

Newbie question...

I've recently started to work with IAsyncEnumerable<T>, and found the lack of ToListAsync, SelectAsync, FirstOrDefaultAsync etc. in official .NET 6 a little surprising.

I then looked into System.Linq.Async via https://github.com/dotnet/reactive and found it quite impenetrable, and ended up writing my own, simple ToListAsync method to satisfy my immediate, simple needs.

Mark Heath's excellent article then helped me understand System.Linq.Async a lot better, so I might use that package next time. But I also saw a link to this repo, which initially looked promising re. providing async versions of familiar LINQ methods. And there's documentation!

But... the docs don't include ToListAsync, SelectAsync, FirstOrDefaultAsync etc. How could this be?

Then I found...

<PackageReference Include="System.Interactive.Async" Version="6.0.1" />
<PackageReference Include="System.Linq.Async" Version="6.0.1" />

:-)

I wonder if this reliance on https://github.com/dotnet/reactive is a good thing... Perhaps it's just a temporary thing(?) It seems to me that we are now reliant on another package, with its own issues (bugs, lack of docs).

In the fullness of time it might be nice if SuperLinq was a one-stop shop, in charge of its own destiny, without the reactive dependency.

If the reactive dependency is likely to continue for a while, should this be signposted on the front page of the repo?

`.CopyTo()`

In order to improve allocations (ex: ArrayPool.Rent()) or to copy data to a specific pre-existing place, it may be useful to copy a sequence. Following APIs to be implemented:

void CopyTo<T>(this IEnumerable<T> source, Span<T> span); 
void CopyTo<T>(this IEnumerable<T> source, IList<T> list);
void CopyTo<T>(this IEnumerable<T> source, IList<T> list, Index index);

Semantics:

  • void CopyTo<T>(this IEnumerable<T> source, IList<T> list); will throw an exception if the source is longer than array. If source is shorter than array, then the remainder of array will be untouched.

Common Generator?

Also, you might want to backlog using a common generator to generate sync and async versions of the same method, instead of needing to copy the code over.

Originally posted by @Arithmomaniac in #2 (comment)

Bug in `.GetShortestPath()`

If, during the processing of traversing, we run out places to go, we should throw an exception instead of returning the last path that we got to.

Add .ScanEx()

The operator name .Scan() is used by System.Interactive(.Async), however behavior is different than expected. Original behavior should be restored under .ScanEx() according to commonly expected behavior of .Scan().

For other notes, see:

Restore .Repeat(IEnumerable<>)

There is a difference between EnumerableEx.Repeat() and MoreEnumerable.Repeat(). The MoreEnumerable version should be restored.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.