Re:Swift and the Legacy of Functional Programming
by antfarm on Monday November 21, 2016 @12:55PM
(#13007388)
It's ugly, but possible:
NSArray *filteredArray = [array filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(id object, NSDictionary *bindings) {
return [object test];
}]];
Re:Swift and the Legacy of Functional Programming
by pjmlp on Monday November 21, 2016 @12:57PM
(#13007400)
You mean something like:
a := #(1 2 3 4 5).
Transcript show: (a printString); cr.
b := a select: [:x | x \\ 2 == 0].
Transcript show: (b printString); cr.
Sadly Objective-C isn't really Smalltalk.
At the moment I'm working in Objective-C, and I literally just wrote a loop to filter an array and form a new array with the results like the one in the example - and god I wish there was an as straight-forward, easily understandable functional way in Obj-C to do it like in the Swift example.
I miss these 'nice' things - I don't need the fully functional Haskell package, but I like having some of the nice things Swift has, just because I got used to them and can actually write and read them better, and it is definitely more elegant!