Is there a version of "andand" monad for Objective-C?

I recently started using Ick 'andand' for Ruby so I can iterate through nested collections faster than before.

Is there a version of this idiom for Objective-C implemented anywhere?

and and in rubygems

+5
source share
1 answer

I'm not a Ruby programmer, so I might miss something subtle, but it seems like it does so that you can safely intercept method calls, even when one method call can return zero. This is built into Objective-C because calling nil methods (actually correctly named for sending messages) is safe and perfectly acceptable. Messages in nil always return zero and are mostly no-op. In Objective-C, this is normal:

id foo = [someObject objectByDoingSomething]; // foo might be nil

id bar = [foo objectByDoingSomethingElse];

// If foo is nil, calling objectByDoingSomethingElse is essentially
// a no-op and returns nil, so bar will be nil
NSLog(@"foo: %@ bar: %@", foo, bar);

Therefore, this is also good, even if objectByDoingSomething can return nil:

id foo = [[someObject objectByDoingSomething] objectByDoingSomethingElse];

From Objective-C Programming language : "In Objective-C, really, you need to send a message to nil-it just has no effect at run time." This document provides more detailed information on the exact behavior of nil invocation methods in Objective-C.

+7
source

All Articles