Code Monkey home page Code Monkey logo

linq's Introduction

#Welcome Linq for Objective-C

Objective-CにLinqの各種メソッドを導入します。

各種メソッドはNSEnumeratorのカテゴリとして実装され、処理自体は.net Frameworkの場合と同様に遅延実行されます。

##使用方法

NSEnumerator+Query.hをインポートして下さい。 NSEnumeratorに各種メソッドが追加されるので操作したいNSArrayやNSDictionaryからobjectEnumeratorによってNSEnumeratorを取得してから操作して下さい。

例)whereによって絞り込みを行う

NSEnumerator *list = [[someArray objectEnumerator]where^BOOL(id item) {
       return (true/* ここに条件を記載 */);}];

絞り込んだリストは列挙される際にフィルタ適用されます。(遅延実行)

toArrayやforEachといったメソッドで即時実行させる事も可能です。

例)otherArrayに含まれないsomeArrayの要素でディレクトリを作成する。

   [[[someArray objectEnumerator] where:^BOOL(id item) {
       return !([otherArray containsObject:item]);
   }] forEach:^(id item) {
       [self makeDir:item];
   }];

いくつかのメソッドはiOSに合う形に変更、追加してあります。 例)ToMutableArray, fromNSDataなど。詳しくはドキュメントをご覧ください。

##実装済みメソッド ###生成系 range:(int)start to:(int)count;
repeat:(id)item count:(int)count;
empty;

###変換系 ofClass: (Class) class;
select: (id(^)(id)) selector;
selectWithIndex: (id(^)(id,int)) selector;
where: (BOOL(^)(id)) predicate;
whereWithIndex: (BOOL(^)(id,int)) predicate;
skip: (int) count;
skipWhile: (BOOL(^)(id)) predicate;
skipWhileWithIndex: (BOOL(^)(id,int)) predicate;
take: (int) count;
takeWhile: (BOOL(^)(id)) predicate;
takeWhileWithIndex: (BOOL(^)(id,int)) predicate;
orderByDescription:(NSSortDescriptor *)firstObj, ... NS_REQUIRES_NIL_TERMINATION;
selectMany: (id(^)(id)) selector;
distinct;
concat:(NSEnumerator *)dst;
union:(NSEnumerator *)dst;
intersect:(NSEnumerator *)dst;
except:(NSEnumerator *)dst;
buffer:(int)count;
toArray;
toMutableArray;
toDictionary: (id(^)(id)) keySelector;
toDictionary: (id(^)(id)) keySelector elementSelector:(id(^)(id)) elementSelector;
toMutableDictionary: (id(^)(id)) keySelector;
toMutableDictionary: (id(^)(id)) keySelector elementSelector:(id(^)(id)) elementSelector;
toData;
toString;

###要素取得系 elementAt:(int)index;
elementOrNilAt:(int)index;
single;
single:(BOOL(^)(id)) predicate;
singleOrNil;
singleOrNil:(BOOL(^)(id)) predicate;
first;
first:(BOOL(^)(id)) predicate;
firstOrNil;
firstOrNil:(BOOL(^)(id)) predicate;
last;
last:(BOOL(^)(id)) predicate;
lastOrNil;
lastOrNil:(BOOL(^)(id)) predicate;

###集計系 count;
all: (BOOL(^)(id)) predicate;
any: (BOOL(^)(id)) predicate;
contains : (id) item;
sequenceEqual: (NSEnumerator *)dst;

###処理関数系 forEach: (void(^)(id item)) action;

##シーケンス生成の追加カテゴリ ###NSData objectEnumerator
###NSString objectEnumerator

linq's People

Contributors

ryujisamejima avatar

Watchers

James Cloos avatar yoshikazum 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.