All Projects → Meituan-Dianping → Easysequence

Meituan-Dianping / Easysequence

Licence: mit
EasySequence is a powerful fundamental library to process sequcence type, such as array, set, dictionary. All type object which conforms to NSFastEnumeration protocol can be initialzed to an EZSequence instance, then you can operation with them. Finally, you can transfer them back to the original type.

Projects that are alternatives of or similar to Easysequence

Fromfrom
A JS library written in TS to transform sequences of data from format to another
Stars: ✭ 462 (+208%)
Mutual labels:  sequence, collection
Fpgo
Monad, Functional Programming features for Golang
Stars: ✭ 165 (+10%)
Mutual labels:  collection, functional-programming
Moses
Utility library for functional programming in Lua
Stars: ✭ 541 (+260.67%)
Mutual labels:  collection, functional-programming
Sequency
⚡️ Type-safe functional sequences for processing iterable data
Stars: ✭ 294 (+96%)
Mutual labels:  sequence, collection
Period
PHP's time range API
Stars: ✭ 616 (+310.67%)
Mutual labels:  sequence, collection
Awesome Ruby
💎 A collection of awesome Ruby libraries, tools, frameworks and software
Stars: ✭ 11,838 (+7792%)
Mutual labels:  collection
Typelang
🌳 A tiny language interpreter implemented purely in TypeScript's type-system
Stars: ✭ 149 (-0.67%)
Mutual labels:  functional-programming
Opensourcegames
Infos and build tips for open source games.
Stars: ✭ 144 (-4%)
Mutual labels:  collection
Awesome Bioinformatics Benchmarks
A curated list of bioinformatics bench-marking papers and resources.
Stars: ✭ 142 (-5.33%)
Mutual labels:  collection
Awesome Cae
A curated list of awesome CAE frameworks, libraries and software.
Stars: ✭ 148 (-1.33%)
Mutual labels:  collection
Cube Composer
A puzzle game inspired by functional programming
Stars: ✭ 1,845 (+1130%)
Mutual labels:  functional-programming
Kingly
Zero-cost state-machine library for robust, testable and portable user interfaces (most machines compile ~1-2KB)
Stars: ✭ 147 (-2%)
Mutual labels:  functional-programming
Best Of
🏆 Discover best-of lists with awesome open-source projects on all kinds of topics.
Stars: ✭ 146 (-2.67%)
Mutual labels:  collection
Munus
Power of object-oriented programming with the elegance of functional programming in PHP.
Stars: ✭ 149 (-0.67%)
Mutual labels:  functional-programming
Parjs
JavaScript parser-combinator library
Stars: ✭ 145 (-3.33%)
Mutual labels:  functional-programming
Meow Mtl
Next Level MTL for Scala
Stars: ✭ 149 (-0.67%)
Mutual labels:  functional-programming
Twcommunities
整理與蒐集台灣社群活動投影片
Stars: ✭ 145 (-3.33%)
Mutual labels:  collection
Awesome Doctrine
A collection of useful Doctrine snippets.
Stars: ✭ 147 (-2%)
Mutual labels:  collection
Doobie
Functional JDBC layer for Scala.
Stars: ✭ 1,910 (+1173.33%)
Mutual labels:  functional-programming
Ip4s
Defines immutable, safe data structures for describing IP addresses, multicast joins, socket addresses and similar IP & network related data types
Stars: ✭ 145 (-3.33%)
Mutual labels:  functional-programming

EasySequence

Build Status Version License Platform codecov

EasySequence is a powerful fundamental library to process sequence type, such as array, set, dictionary. Each type of object which conforms to NSFastEnumeration protocol can be initialzed to an EZSequence instance, then you can operate with it. Finally, you can transfer it back to the original type.

Requirements

iOS 8.0 or later.

Installation

EasySequence is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'EasySequence'

To run the example project, clone the repo, and run pod install from the Example directory first.

Features

Creating

  • can be initialized from any object which conforms to NSFastEnumeration protocol.

Enumerating

  • enumerate using forEach:
  • enumerate using forEachWithIndex:
  • enumerate using fast enumeration
  • enumerate using NSEnumerator

Operations

  • map
  • flatten map
  • filter
  • select
  • reject
  • take
  • skip
  • any
  • zip
  • reduce
  • group by
  • first object
  • first object where
  • first index where

Transfer

  • An object which conforms to EZSTransfer protocol can get an instance which transfer from EZSequence.

Thread-Safety Type

We provides thread-safety types as below:

  • EZSArray
  • EZSWeakArray
  • EZSOrderedSet
  • EZSWeakOrderedSet
  • EZSQueue

Weak Container

EZSWeakArray and EZSWeakOrderedSet form weak reference to their's items.

Example

Create a sequence

A sequence, represented by the EZSequence type, is a particular order in which ralated objects, or objects follow each other. For example, a NSArray or a NSSet is sequence ather than EZSequence.

An EZSequence can be initialized from any object which conforms to NSFastEnumeration protocol.


NSArray *array = @[@1, @2, @3];
EZSequence *sequence = [[EZSequence alloc] initWithOriginSequence:array];

Enumerating

  • Enumerate using fast enumeration
EZSequence *sequence = [[EZSequence alloc] initWithOriginSequence:@[@1, @2, @3]];
NSMutableArray *receive = [NSMutableArray array];
for (id item in sequence) {
    [receive addObject:item];
}
  • Enumerate using NSEnumerator
EZSequence<NSNumber *> *sequence = [[EZSequence alloc] initWithOriginSequence:@[@1, @2, @3]];
NSMutableArray<NSNumber *> *receive = [NSMutableArray array];

NSEnumerator<NSNumber *> *enumerator = [sequence objectEnumerator];
for (id item in enumerator) {
    [receive addObject:item];
}
  • Enumerate using block-based enumeration
EZSequence<NSNumber *> *sequence = [[EZSequence alloc] initWithOriginSequence:@[@1, @2, @3]];
NSMutableArray *receive = [NSMutableArray array];
[sequence forEach:^(NSNumber *item) {
    [receive addObject:item];
}];

[sequence forEachWithIndex:^(NSNumber * _Nonnull item, NSUInteger index) {
    [receive addObject:item];
}];

[sequence forEachWithIndexAndStop:^(NSNumber * _Nonnull item, NSUInteger index, BOOL * _Nonnull stop) {
    if (index == 2) {
        *stop = YES;
    }
    [receive addObject:item];
}];

Operations

  • map
EZSequence<NSString *> *sequence = EZS_Sequence(@[@"111", @"222", @"333"]);
EZSequence<NSNumber *> *mappedSequence = [sequence map:^id _Nonnull(NSString * _Nonnull value) {
    return @(value.integerValue);
}];
// mappedSequence => @111, @222, @333
  • select
EZSequence<NSNumber *> *sequence = [@[@1, @2, @3, @4, @5, @6] EZS_asSequence];
EZSequence<NSNumber *> *oddNumbers = [sequence select:^BOOL(NSNumber * _Nonnull value) {
    return value.integerValue % 2 == 1;
}];
// oddNumbers => @1, @3, @5
  • filter
EZSequence *seq = EZS_Sequence(@[@"1", @"2", @"3", @"4", @"5"]);
EZSequence *filteredSeq = [seq filter:EZS_not(EZS_isEqual(@"4"))];
// filteredSeq = > @"1", @"2", @"3", @"5"
  • zip
NSArray *a = @[@1, @2, @3];
NSArray *b = @[@"a", @"b"];
EZSequence<EZSequence *> *zippedSeq = [EZSequence zip:@[a, b]];
// zippedSeq => @[@1, @"a"], @[@2, @"b"]

For more examples and help, see also our unit test and API comments.

Transfer Protocol

An object which conforms to EZSTransfer protocol can get an instance which transfer from EZSequence.


EZSequence *sequence = [[EZSequence alloc] initWithOriginSequence:@[@1, @2, @3, @2]];

// transfer to a `NSArray`
NSArray *array = [sequence as:NSArray.class];
// array => @1, @2, @3, @2

// transfer to a `NSSet`
NSSet *set = [sequence as:NSSet.class];
// set => @1, @2, @3

// transfer to a `NSOrderedSet`
NSOrderedSet *orderedSet = [sequence as:NSOrderedSet.class];
// orderedSet => @1, @2, @3

Author

William Zang, [email protected]
姜沂, [email protected]
Qin Hong, [email protected]
SketchK, [email protected]

License

EasySequence is available under the MIT license. See the LICENSE file for more info.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].