Git Product home page Git Product logo

invio.extensions.linq's People

Contributors

carusology avatar rokadias avatar sflanker avatar

Watchers

 avatar  avatar  avatar  avatar

invio.extensions.linq's Issues

Add calculated 'HasMore' property to 'PaginatedResult'

Background

When returning paginated results, one often wants to know "are there any more results after this page?" We do all the time in our closed source code. Consumers of the PaginatedResult<T> value object can use the Offset, Results.Count, and Total properties to deterministically calculate whether or not there are more results after the current page in the overall list of results. However, rather than require all consumers of this value object to implement this calculation themselves, let's provide it as a first class property.

Task

  • Enhance PaginatedResult<T> to throw exceptions on invalid input that prevent a deterministic calculation of HasMore (null result set, negative total, result set + offset > total, etc.)
  • Enhance PaginationResult<T> to include a HasMore property that is calculated like so:
hasMore = (page.Offset + page.Results.Count) < page.Total;

Add `.Zip` extension to Enumerable.Zip that defaults to Tuple.Create

Background

Ah, Zip() is a wonder little extension method on top of IEnumerable<T> to combine two IEnumerable<T> implementations together. Unfortunately, the default implementation requires all consumers to plug in a Func<TFirst, TSecond, TResult> implementation on how to combine those two enumerable together. This means if you want to combine two enumerables together into tuples, you have to do this:

var foo = new int[] { 1, 2, 3 };
var bar = new string[] { "4", "5", "6" };
IEnumerable<Tuple<int, string>> zipped = foo.Zip(bar, Tuple.Create);

This should be the default.

Task

Add an extension method to IEnumerable<T> called Zip that uses Tuple.Create as the default implementation. Then the above example can be transformed to this:

var foo = new int[] { 1, 2, 3 };
var bar = new string[] { "4", "5", "6" };
IEnumerable<Tuple<int, string>> zipped = foo.Zip(bar);

Add `Subsequences` extension to `IEnumerable<T>`

Another carry over from haskell.

Background

I have a situation way down stream that, given an enumerable of objects, I want all possible "subsequences" of that list of objects. In discrete and combinatorial algebra, this would be considered all subsets, including the identity, of a parent set. I'm using the term "subsequences" since this is the name of this function in haskell, and I already named "cycle" based upon its equivalent name in haskell. Therefore it makes sense to me to keep this consistent.

Task

Add the following extension method to IEnumerable<T>:

// Input: [ "foo", "bar", "biz" ]
// Output: [[], [ "foo" ], [ "bar" ], [ "biz" ], [ "foo", "bar" ], [ "foo", "biz" ], [ "bar", "biz" ], [ "foo", "bar", "biz" ]]

public static IEnumerable<IEnumerable<T>> Subsequences(this IEnumerable<T> source);

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.