Documentation

ETCollectionHOM

ETCollectionHOM

Higher-order messaging additions to ETCollection.

AuthorsGenerated by qmathe
Declared inETCollection+HOM.h

Default

- (id) mappedCollection

Returns a proxy object on which methods can be called. These methods will cause a collection to be returned containing the elements of the original collection mapped by the method call.

Example: addresses = [[people mappedCollection] address]; will cause addresses to be a collection created by sending -address to every element in people.

Note: Can be used to send the same message to multiple objects even if the message returns void, then the result is not a new collection but nil. For example, [[people mappedCollection] setCity: @"New York"] .

    - (id) leftFold

    Returns a proxy object that can be used to perform a left fold on the collection. The value of the first argument of any method used as a folding method is taken to be the initial value of the accumulator, with the accumulator being used as the receiver of the folding method.

    Example: total = [[salaries leftFold] addAmount: nullSalary]; will compute total of all elements in salaries by using the -addAmount: message.

      - (id) rightFold

      Returns a proxy object that can be used to perform a right fold on the collection. The value of the first argument of any method used as a folding method is taken to be the initial value of the accumulator, with the accumulator being used as the argument of the folding method.

      Example: If characters is an ordered collection containing "x", "y" and "z" (in that order), [[characters rightFold] stringByAppendingString: @": end"]; will produce "xyz: end".

        - (id) zippedCollectionWithCollection: (id )aCollection

        Returns a proxy object the will use the next message received to coalesce the receiver and aCollection into one collection by sending the message to every element of the receiver with the corresponding element of the second collection as an argument. The first argument (after the implicit receiver and selector arguments) of the message is thus ignored. The operation will stop at the end of the shorter collection.

        Example: If collection A contains "foo" and "FOO", and collection B "bar" and "BAR", [[A zippedCollectionWithCollection: B] stringByAppendingString: nil]; will produce a collection containing "foobar" and "FOOBAR".

          - (id) mappedCollectionWithBlock: (id)aBlock

          Returns a collection with each element of the original collection mapped by applying aBlock where aBlock takes one argument of type id and returns id.

            - (id) leftFoldWithInitialValue: (id)initialValue intoBlock: (id)aBlock

            Folds the collection by applying aBlock consecutively with the accumulator as the first and each element as the second argument of the block.

              - (id) rightFoldWithInitialValue: (id)initialValue intoBlock: (id)aBlock

              Folds the collection by applying aBlock consecutively with the accumulator as the second and each element (beginning with the last) as the first argument of the block.

                - (id) zippedCollectionWithCollection: (id )aCollection andBlock: (id)aBlock

                Coalesces the receiver and the collection named by aCollection into one collection by applying aBlock (where aBlock takes two arguments of type id) to all element-pairs built from the receiver and aCollection. The operation will stop at the end of the shorter collection.

                Example: For A={a,b} and B={c,d,e} C = [A zippedCollectionWithCollection: B andBlock: ^ NSString* (NSString *foo, NSString *bar) {return [foo stringByAppendingString: bar];}]; will result in C={ac,bd}.

                  - (id) filteredCollectionWithBlock: (BOOL(^)(id))aBlock

                  Returns a collection containing all elements of the original collection that respond with YES to aBlock.

                    - (id) filteredOutCollectionWithBlock: (BOOL(^)(id))aBlock

                    Returns a collection containing all elements of the original collection that respond with NO to aBlock.