- Most of the LINQ methods(60+) are supported.
- Chaining of LINQ methods are supported.
- Lambda is supported(slow).
For more examples, please see the main.c file.
#include <gc.h>
#include "ArrayList.h"
#include "linq.h"
bool WhereCallback(void *item) {
char *str= (char *)item;
return str[0] == 'h';
}
void *SelectCallback(void *item) {
return newStr("%s_1", (char *)item);
}
ArrayList testLinq(ArrayList array) {
Linq *lq = From(array);
ArrayList result =
lq
->Where(lq, WhereCallback)
->Select(lq, SelectCallback)
->ToArray(lq);
return result;
}
int main() {
GC_INIT();
char *str1 = "huang", *str2 = "hai", *str3 = "feng";
ArrayList array = arrlist_new();
arrlist_append(array, str1);
arrlist_append(array, str2);
arrlist_append(array, str3);
ArrayList result = testLinq(array);
for(int i = 0; i < arrlist_size(result); i++) {
printf("%s\n", arrlist_get(result, i));
}
return 0;
}
ArrayList testLinq(ArrayList array) {
Linq *lq = From(array);
ArrayList result =
lq
->Where(lq,
lambda(bool, (void *item) {
char *str= (char *)item;
return str[0] == 'h';
}))
->Select(lq,
lambda(void *, (void *item) {
return newStr("%s_1", (char *)item);
}))
->ToArray(lq);
return result;
}
int main() {
GC_INIT();
char *str1 = "huang", *str2 = "hai", *str3 = "feng";
ArrayList array = arrlist_new();
arrlist_append(array, str1);
arrlist_append(array, str2);
arrlist_append(array, str3);
ArrayList result = testLinq(array);
for(int i = 0; i < arrlist_size(result); i++) {
printf("%s\n", arrlist_get(result, i));
}
return 0;
}
#define LINQ_PTR lq
bool WhereCallback(void *item) {
char *str= (char *)item;
return str[0] == 'h';
}
void *SelectCallback(void *item) {
return newStr("%s_1", (char *)item);
}
ArrayList testLinq(ArrayList array) {
Linq *lq = From(array);
ArrayList result =
lq
->WHERE(WhereCallback)
->SELECT(SelectCallback)
->TO_ARRAY();
return result;
}
int main(int argc, char **argv) {
GC_INIT();
char *str1 = "huang", *str2 = "hai", *str3 = "feng";
ArrayList array = arrlist_new();
arrlist_append(array, str1);
arrlist_append(array, str2);
arrlist_append(array, str3);
ArrayList result = testLinq(array);
for(int i = 0; i < arrlist_size(result); i++) {
printf("%s\n", arrlist_get(result, i));
}
return 0;
}
As for the garbage collect, you need to install Boehm GC
.
# yum install gc-devel # RedHat family
# apt-get install libgc-dev # Debian family
- Where
- WhereIndexed
- Select
- SelectIndexed
- SelectMany
- SelectManyIndexed
- SelectManyBy
- FirstOrDefault
- LastOrDefault
- Take
- TakeEvery
- TakeWhile
- TakeWhileIndexed
- TakeExceptLast
- TakeFromLast
- Skip
- SkipWhile
- SkipWhileIndexed
- Any
- All
- Reverse
- IndexOf
- LastIndexOf
- Concat
- Except
- Union
- Intersect
- SumInts
- SumFloats
- MaxInts
- MaxFloats
- MinInts
- MinFloats
- AverageInts
- AverageFloats
- Max
- Min
- OrderBy
- OrderByDesc
- GroupBy
- Zip
- Single
- SingleWith
- Contains
- Count
- CountWith
- JoinStr
- Join
- GroupJoin
- Aggregate
- AggregateWithSeed
- AggregateWithSeedBy
- SequenceEqual
- Prepend
- Append
- ForEach
- AlternateBefore
- AlternateAfter
- Shuffle
- Slice
- Pad
- PadBy
- Println
MIT