Coder Social home page Coder Social logo

linq_php's Introduction

Linq in PHP

This is PHP library, that allows to query collections following C# LINQ patterns. The standard LINQ methods are implemented with interfaces adopted to the PHP language. The full list of these methods can be taken from MSDN, .NET 4.5. The modified interfaces of these methods are located in the Qmaker\Linq\Operation namespace. At the present time the library requires PHP of the version 5.4.

Lambda expression

The class Lambda allows to build lambda expressions, anonymous functions with stored structure. The class creates a callable object, which can be used in LINQ methods as callable criteria, predicate or expression. Thus,

$f = Lambda::v()->add()->v()->mult(12)->gt(36);

is equivalent to

$f = function ($x) { return $x + $x*12 > 36; };

More information and examples will be added later. See unit tests.

Linq

The following methods are implemented

  • Aggregation — aggregate, average, min, max, sum, count
  • Concatenation — concat, zip
  • Element — elementAt, elementAtOrDefault, first, firstOrDefault, last, lastOrDefault, single, singleOrDefault
  • Equality — isEqual
  • Filtering — ofType, where
  • Generation — from, range, repeat
  • Grouping — groupBy
  • Joining — product, join, joinOuter, groupJoin
  • Partitioning — skip, skipWhile, take, takeWhile
  • Projection — select, selectMany, cast
  • Quantifier — all, any, contains
  • Set — distinct, intersect, except, union
  • Sorting — orderBy, orderByDescending, thenBy, thenByDescending, reverse, order
  • Others — toArray, toList, each

The suited types for the source in the corresponding methods (like from) are array, \Iterator, \IteratorAggregate or callable variable. As an expression one can also specify string, callable variable, array or lambda expression LambdaInterface. The following example

$f = Linq::from([1, 2, 3, 4])->where(Lambda::v()->gt(2))->sum(Lambda::v()->mult(2));

will return 14. More information and examples will be added later. See unit tests.

Iterators

The iterators are the keystone of this library. Within the project multiple iterators were additionally implemented

  • CallbackFilterIterator Filtering items using multiple callbacks

  • CallbackIterator Generate the sequence of the elements using a callback

  • GroupingIterator Group elements by key

  • IndexIterator Sort elements by key

  • JoinIterator, OuterJoinIterator Inner/outer join of two iterators

  • LimitIterator Iterator over the given range

  • ProductIterator Cross-product of multiple iterators

  • SkipIterator Skip items while some criteria is true

  • TakeIterator Take items while some criteria is true

  • ProjectionIterator Convert current values or keys

  • ReverseIterator Reverse order

  • DistinctIterator, ExceptIterator, IntersectIterator Sets operations

  • LazyIterator Build inner iterator when the first item will be requested

  • VariableIterator Re-assign the inner iterator

linq_php's People

Contributors

morgen2009 avatar

Watchers

 avatar  avatar

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.