• Stars
    star
    583
  • Rank 76,663 (Top 2 %)
  • Language
    C++
  • License
    MIT License
  • Created over 12 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Simplest C++ header-only LINQ template library

boolinq 3.0

CI Status Coverage Status

Super tiny C++11 single-file header-only LINQ template library

Just imagine .NET Framework LINQ support for STL/Qt collections :)

Get source code here: boolinq.h

Wanna demo?

Example with integers

int src[] = {1,2,3,4,5,6,7,8};
auto dst = from(src).where( [](int a) { return a % 2 == 1; })      // 1,3,5,7
                    .select([](int a) { return a * 2; })           // 2,6,10,14
                    .where( [](int a) { return a > 2 && a < 12; }) // 6,10
                    .toStdVector();

// dst type: std::vector<int>
// dst items: 6,10

Example with structs

struct Man {
    std::string name;
    int age;
};

Man src[] = {
    {"Kevin",14},
    {"Anton",18},
    {"Agata",17},
    {"Terra",20},
    {"Layer",15},
};

auto dst = from(src).where(  [](const Man & man) { return man.age < 18; })
                    .orderBy([](const Man & man) { return man.age; })
                    .select( [](const Man & man) { return man.name; })
                    .toStdVector();

// dst type: std::vector<std::string>
// dst items: "Kevin", "Layer", "Agata"

Interesting example

struct Message {
    std::string PhoneA;
    std::string PhoneB;
    std::string Text;
};

Message messages[] = {
    {"Anton","Troll","Hello, friend!"},
    {"Denis","Wride","OLOLO"},
    {"Anton","Papay","WTF?"},
    {"Denis","Maloy","How r u?"},
    {"Denis","Wride","Param-pareram!"},
};

int DenisUniqueContactCount =
    from(messages).where(   [](const Message & msg) { return msg.PhoneA == "Denis"; })
                  .distinct([](const Message & msg) { return msg.PhoneB; })
                  .count();

// DenisUniqueContactCount == 2    

Test in C++14 using auto

The following test requires C++14 GroupByTestComplex.cpp It uses auto in order to avoid a very long lambda argument type. The return type of a function or lambda expression can be deduced by its operand since C++14. The CMake file is changed so that this test runs with C++14.

TEST(GroupBy, CountTaxes)
{
    struct Tax {
        std::string name;
        int amount_1;
        int amount_2;

        bool operator ==(const Tax & tax) const {
            return name == tax.name
                && amount_1 == tax.amount_1
                && amount_2 == tax.amount_2;
        }
    };

    std::vector<Tax> taxes = {
        {"tax 1", 1, 1},
        {"tax 2", 1, 1},
        {"tax 1", 2, 2},
        {"tax 3", 3, 3},
        {"tax 1", 4, 4},
    };

    Tax ans[] = {
        {"tax 1", 7, 7},
        {"tax 2", 1, 1},
        {"tax 3", 3, 3},
    };

    auto dst = from(taxes)
        .groupBy([](const Tax & a){return a.name;})
        .select([](const auto & pair){ // use of auto here needs c++14
            return Tax {
                pair.first,
                pair.second.sum([](const Tax & a){return a.amount_1;}),
                pair.second.sum([](const Tax & a){return a.amount_2;})
            };
        });

    CheckRangeEqArray(dst, ans);
}

Containers supported?

  • C++: Native arrays, pairs of pointers
  • STL: list, stack, queue, vector, deque, set, map, any compatible ....
  • Qt: QList, QVector, QSet, QMap.

Operators supported?

Filters and reorders:

  • where(predicate), where_i(predicate)
  • take(count), takeWhile(predicate), takeWhile_i(predicate)
  • skip(count), skipWhile(predicate), skipWhile_i(predicate)
  • orderBy(), orderBy(transform)
  • distinct(), distinct(transform)
  • append(items), prepend(items)
  • concat(linq)
  • reverse()
  • cast<T>()

Transformers:

  • select(transform), select_i(transform)
  • groupBy(transform)
  • selectMany(transfom)

Aggregators:

  • all(), all(predicate)
  • any(), any(lambda)
  • sum(), sum<T>(), sum(lambda)
  • avg(), avg<T>(), avg(lambda)
  • min(), min(lambda)
  • max(), max(lambda)
  • count(), count(value), count(predicate)
  • contains(value)
  • elementAt(index)
  • first(), first(filter), firstOrDefault(), firstOrDefault(filter)
  • last(), last(filter), lastOrDefault(), lastOrDefault(filter)
  • toStdSet(), toStdList(), toStdDeque(), toStdVector()

Bits and Bytes:

  • bytes<T>(ByteDirection?)
  • unbytes<T>(ByteDirection?)
  • bits(BitsDirection?, BytesDirection?)
  • unbits<T = unsigned char>(BitsDirection?, BytesDirection?)

Coming soon:

  • gz()
  • ungz()
  • leftJoin
  • rightJoin
  • crossJoin
  • fullJoin

More Repositories

1

ABCalendarPicker

Fully configurable iOS calendar UI component with multiple layouts and smooth animations.
Objective-C
712
star
2

NSEnumeratorLinq

NSEnumerator LINQ category
Objective-C
208
star
3

LaunchScreenViewController

iOS View Controller for loading default launch screen in app and maybe to add some animations to it
Objective-C
186
star
4

Unipool

Solidity
73
star
5

UIView-FastScreenshot

The fastest way to get iOS screenshot
C
53
star
6

UIImage-DecompressAndMap

iOS library for quickly displaying images while scrolling
Objective-C
52
star
7

MissingAnchors

Backport of Apple NSLayoutAnchor API to iOS7 and some missings like `sizeAnchor` and `edgesAnchor`
Objective-C
37
star
8

Cliple

Simple clipboard manage app for Mac OS X
C
32
star
9

iBackupMounter

Just mount iOS iTunes backups to OS X file system
Objective-C
30
star
10

DeluxeInjection

Simplest Objective-C Dependency Injection (DI๐Ÿ’‰) implementation ever
Objective-C
29
star
11

parity-trace-decoder

Parity Trace Decoder
JavaScript
26
star
12

Mattericon

Native OS X client to drag-n-drop Material Icons to Sketch
Objective-C
26
star
13

GasTray

Simple gas tray app for macOS
Objective-C
20
star
14

ABIntentions

Collection of iOS intentions. Inspired by http://bendyworks.com/geekville/articles/2014/2/single-responsibility-principle-ios and http://chris.eidhof.nl/posts/intentions.html
Objective-C
14
star
15

NSData-AsyncCacher

NSData category for async loading data from url and calling block. Requested data is cached with NSCache and can be requested multiple times simultaneously.
Objective-C
12
star
16

ABStaticTableViewController

Dynamically hide rows and sections in static UITableView inside UITableViewController.
Objective-C
11
star
17

ShardedToken

JavaScript
11
star
18

CroptateView

Simple view allowing to crop and rotate photos
Objective-C
10
star
19

RTLButton

UIButton subclass with image and title aligned Right To Left
Ruby
10
star
20

zolidity

Simplest Solidity compiler
TypeScript
9
star
21

Soliditemp

TruffleFramework template with travis-ci.org and coveralls.io configured
Solidity
9
star
22

CALayer-AutoresizingMask

Add UIViewAutoresize support to iOS CALayers and fast UIView to CALayer conversion method
Objective-C
8
star
23

ERC2608

Token Standard with Safe Arbitrary Call
Solidity
8
star
24

PieDisk

Cross-platform pie-chart disk space analyzer
C++
8
star
25

LeaderboardKit

iOS and OSX social leaderboards and highscore push notifications on top of Apple CloudKit
Objective-C
5
star
26

AirPlayMe

I am trying to stream any video file to my Apple TV step by step
5
star
27

UIView-IBDesignable

IB_DESIGNABLE category to UIView
Objective-C
5
star
28

ABCollectionViewFRC

NSFetchedResultsControllerDelegate wrapper for UICollectionView animated changes
Ruby
5
star
29

MultiToken

ERC20 token solidity smart contract allowing aggreagate ERC20 tokens
JavaScript
5
star
30

k29

256-byte assembly gradient spiral with controls
Assembly
3
star
31

UINavigationController-StatusBar

UINavigationController with overloaded methods to provide child status bar state
Objective-C
3
star
32

MusicFinder

Find artists by name, browse albums and songs with MusicBrainz.org web service.
Objective-C
3
star
33

Xross

All-directions-enabled UIPageViewController
Objective-C
2
star
34

Blockhashes

Solidity
2
star
35

TypoToken

JavaScript
2
star
36

k06a

2
star
37

DailyPhoto

Demo RSS image viewer for http://fotki.yandex.ru/calendar/rss2
Objective-C
1
star
38

reghope

Automatically exported from code.google.com/p/reghope
C++
1
star
39

truffle-string-multi-literal

JavaScript
1
star
40

Uzh

Simple snake game for iOS
Objective-C
1
star
41

IntInt

Extra efficient ะก++ BigInt implementation
C++
1
star
42

stliw

Automatically exported from code.google.com/p/stliw
C++
1
star
43

ML-2016

HTML
1
star
44

RitM

RitM in the Middle โ€“ My diploma project for network traffic retransmission
C++
1
star
45

NSNull-SelfOrNil

Simple category for NSNull to return nil on self method call
Ruby
1
star
46

ABStackedRollView

Simple UICollectionView son, which looks like two piles exchanging their sheets.
Objective-C
1
star