Skip to content
This repository has been archived by the owner on Nov 11, 2021. It is now read-only.

Index-less versions of map, filter, each etc. by default; declare eachWithIndex #71

Open
fatuhoku opened this issue Jul 7, 2014 · 1 comment

Comments

@fatuhoku
Copy link

fatuhoku commented Jul 7, 2014

Very very often, it is unnecessary to take into account the index of the element when mapping. For instance:

    [[foos filter:^BOOL(NSString *foo) {
        return [foo length] > 0;
    }] each:^(NSString *bar) {
        // do something with bar
    }];

This code works perfectly with well with Functional.m. However, under Overline, we must also define a NSUInteger parameter, which makes the statement less readable.

    [[foos filter:^BOOL(NSString *foo, NSUInteger __unused) {
        return [foo length] > 0;
    }] each:^(NSString *bar, NSUInteger __unused) {
        // do something with bar
    }];

I think Overline should consider following the same interface as Functional.m.

@interface NSArray(F)
    ...
    - (void) each:(VoidIteratorArrayBlock) block;
    - (void) eachWithIndex:(VoidIteratorArrayWithIndexBlock) block;   // ***
    - (NSArray *) map:(MapArrayBlock) block;
    ...
@end

In fact, the act of 'mapping' data from one array into another should never depend on its position and thus there should not be a mapWithIndex: method at all.

@fatuhoku fatuhoku changed the title Index-less versions of map, filter, each etc. Index-less versions of map, filter, each etc. by default; declare eachWithIndex Jul 7, 2014
@fatuhoku
Copy link
Author

fatuhoku commented Jul 8, 2014

I guess in this case I could use Overline-BlocksKit in combination with Functional.m to avoid using the Overline implementations.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant