invio / invio.extensions.linq Goto Github PK
View Code? Open in Web Editor NEWA collection of extension methods and helper classes for working with Linq.
License: MIT License
A collection of extension methods and helper classes for working with Linq.
License: MIT License
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
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.)PaginationResult<T>
to include a HasMore
property that is calculated like so:hasMore = (page.Offset + page.Results.Count) < page.Total;
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);
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);
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.