GithubHelp home page GithubHelp logo

antmd / rxcollections Goto Github PK

View Code? Open in Web Editor NEW

This project forked from robrix/rxcollections

0.0 2.0 0.0 1.46 MB

higher-order lazy evaluation for Cocoa

License: BSD 3-Clause "New" or "Revised" License

rxcollections's Introduction

RXCollections

Lazily-evaluated (when feasible) higher-order functions for Cocoa collections (including your own), with as little chaff as possible.

In short:

#import <RXCollections/RXCollections.h>

…
RXMap(people, ^(Pal *each) { return each.phoneNumber; });

RXFilter(ungulates, ^(id<Ungulate> each) { return each.stomachCount == 4; });

RXFold(chunksOfText, @"", ^(NSString *full, NSString *each) { return [full stringByAppendingString:each]; });

RXLinearSearch(scientists, ^(Scientist *each) { return [each.name isEqualToString:@"Richard Feynman"]; });

RXConvolveWith(@[names, addresses, phoneNumbers], ^(NSUInteger count, id const objects[count]) {
	return [BusinessCard withName:objects[0] address:objects[1] phoneNumber:object[2]];
});

(Yeah, yeah, you can call it RXZipWith instead if you like that so much better.)

Collections that can be created

Maps and filters return enumerations, which can be made into concrete collections with the RXConstruct… functions, e.g. RXConstructArray(RXMap(…)). It doesn’t matter what you’re mapping or filtering if you’re constructing a set or array; constructing dictionaries, however, requires the enumeration to produce RXKeyValuePair-conformant objects so that it can associate the keys and values it inserts.

Collections that can be traversed

RXMap, RXFold, RXFilter, RXLinearSearch can traverse anything conforming to NSFastEnumeration (which includes, among other things, NSEnumerator and NSManagedObjectModel). The returned object can itself be enumerated, as well as composed with other traversals safely and cleanly.

Notes

  • Maps, filters, and convolutions are lazily evaluated. RXConstructArray lazily constructs an array from its source enumeration.

  • More documentation is available in the header files.

  • The included Xcode target compiles a framework and a dylib, but you can also just link the source files in.

Future

  • Depth-first tree traversals with prefix/infix/postfix ordering. As a corollary, removing RXRecursiveEnumerator.

  • Concatenation of traversals.

  • Combined RXConstruct… and RXMap/RXFilter shorthands, e.g. RXMapToArray()?

rxcollections's People

Contributors

robrix avatar codafi avatar cbowns avatar

Watchers

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