是否有Objective-C的'andand'monad版本?

Jam*_*mes 5 monads objective-c

我最近开始使用Ick的'andand'用于Ruby,所以我可以比以前更容易地遍历嵌套集合.

是否有任何版本的Objective-C在任何地方实现?

并且在rubygems

And*_*sen 7

我不是一个Ruby程序员,所以我可能会遗漏一些微妙的东西,但它似乎并且使得它可以安全地链接方法调用,即使一个方法调用可能返回nil.这是在Objective-C中内置的,因为调用方法(实际上恰当地称为发送消息)nil是安全且完全可接受的.发送给nil的消息总是返回nil,基本上是no-op.在Objective-C中这很好:

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);
Run Code Online (Sandbox Code Playgroud)

因此,即使objectByDoingSomething可能返回nil,这也很好:

id foo = [[someObject objectByDoingSomething] objectByDoingSomethingElse];
Run Code Online (Sandbox Code Playgroud)

来自Objective-C编程语言:"在Objective-C中,将消息发送到nil是有效的 - 它在运行时根本没有效果." 该文档包含有关在Objective-C中调用nil的方法的确切行为的更多细节.