Index: src/OFArray.m ================================================================== --- src/OFArray.m +++ src/OFArray.m @@ -411,12 +411,12 @@ append(ret, @selector(appendString:), [cArray[i] description]); [pool release]; /* - * Class swizzle the string to be immutable. We declared the return type - * to be OFString*, so it can't be modified anyway. But not swizzling it + * Class swizzle the array to be immutable. We declared the return type + * to be OFArray*, so it can't be modified anyway. But not swizzling it * would create a real copy each time -[copy] is called. */ ret->isa = [OFString class]; return ret; } @@ -493,12 +493,12 @@ [pool release]; [ret autorelease]; /* - * Class swizzle the string to be immutable. We declared the return type - * to be OFString*, so it can't be modified anyway. But not swizzling it + * Class swizzle the array to be immutable. We declared the return type + * to be OFArray*, so it can't be modified anyway. But not swizzling it * would create a real copy each time -[copy] is called. */ ret->isa = [OFString class]; return ret; } Index: src/OFSet.h ================================================================== --- src/OFSet.h +++ src/OFSet.h @@ -20,10 +20,15 @@ #import "OFCollection.h" @class OFMutableDictionary; @class OFArray; +#ifdef OF_HAVE_BLOCKS +typedef void (^of_set_enumeration_block_t)(id object, BOOL *stop); +typedef BOOL (^of_set_filter_block_t)(id object); +#endif + /** * \brief An unordered set of unique objects. */ @interface OFSet: OFObject { @@ -109,8 +114,26 @@ * * \return Whether the receiver and the specified set have at least one object * in common */ - (BOOL)intersectsSet: (OFSet*)set; + +#ifdef OF_HAVE_BLOCKS +/** + * \brief Executes a block for each object. + * + * \param block The block to execute for each object + */ +- (void)enumerateObjectsUsingBlock: (of_set_enumeration_block_t)block; + +/** + * \brief Returns a new set, only containing the objects for which the block + * returns YES. + * + * \param block A block which determines if the object should be in the new set + * \return A new, autoreleased OFSet + */ +- (OFSet*)filteredSetUsingBlock: (of_set_filter_block_t)block; +#endif @end #import "OFMutableSet.h" Index: src/OFSet.m ================================================================== --- src/OFSet.m +++ src/OFSet.m @@ -305,6 +305,35 @@ objects[i] = object; } return count; } + +#ifdef OF_HAVE_BLOCKS +- (void)enumerateObjectsUsingBlock: (of_set_enumeration_block_t)block +{ + [dictionary enumerateKeysAndObjectsUsingBlock: ^ (id key, id object, + BOOL *stop) { + block(key, stop); + }]; +} + +- (OFSet*)filteredSetUsingBlock: (of_set_filter_block_t)block +{ + OFMutableSet *ret = [OFMutableSet set]; + + [dictionary enumerateKeysAndObjectsUsingBlock: ^ (id key, id object, + BOOL *stop) { + if (block(key)) + [ret addObject: key]; + }]; + + /* + * Class swizzle the set to be immutable. We declared the return type + * to be OFSet*, so it can't be modified anyway. But not swizzling it + * would create a real copy each time -[copy] is called. + */ + ret->isa = [OFSet class]; + return ret; +} +#endif @end