-
Notifications
You must be signed in to change notification settings - Fork 0
/
README
104 lines (76 loc) · 4.16 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
This project is a collection of Objective-C Classes
that come in handy for Haskell programmers
that are interested in developing with the iPhone SDK
... and other programmers with a functional background.
For procedural programmers they should also be an enrichment
as you can save writing unnecessary code. If you like the ideas here
please have a look at a functional language as doing so will shurely
enlighten your view on programming.
Status of the project: Some functions were written (with care)
but not tested. While this does usually work good for Haskell
it often fails for less abstract languages like Objective-C.
Be warned and make shure your code works as expected.
A last word on this project: You are welcome to get involved or
give feedback of any kind. You can use the mail form at
http://n-mayr.de/ . Put "objc4hs" in the "Betreff" (=Subject) for
extra speedy responses.
Lets dive right in.
The Class extenstions 'OHMapZipCategories' contains some friends of the
"makeObjectsPerformSelector:"-Method that Apple failed to put in.
People already familiar with the 'map', 'zip' and 'zipWith' functions will
know what these Methods do and will find the right type for their needs.
You should be able to write much less loops by hand. But beware that
the compiler does not check if a selector can be performed by any object.
If you misspell a name you will encounter the problem at runtime.
Fortunately this kind of error is easy to fix as the debug message upon
crash will tell you exactly where the problem lies.
Here are some examples:
(1) NSArray *results = [someArray mapSel:@selector(someSelector)];
(2) NSArray *results = [someArray mapSel:@selector(someSelector)
obj:someObject];
(3) NSArray *results = [someObject mapSel:@selector(someSelector)
arr:someArray;
(4) NSArray *zippedArrays = [someArray zip:anotherArray];
(5) NSArray *zippedArrays = [someArray zipWith:@selector(someSelector
arr:anotherArray];
Method (1) does indeed differ form "makeObjectsPerformSelector:". It does
not only perform the selector it also collects the results and returns
it as an (NSArray *).
(2) As you might have guessed, there is also a correspondent for
"makeObjectsPerformSelector:withObjects:".
There are also methods (3) that work on one object and performs one of its
selectors with an array of objects.
(4) "zip:" will create an OHTupel which is just an Object representing a
Tuple. The new NSArray has the length of the shorter of the given arrays.
(5) "zipWith:" will call the selector on an object of the first array with
the corresponding object of the second array. The results are returned.
All Methods exist in a variant that returns (void) - if you are just
interested in the side effects. Of course "makeObjectsPerformSelector:" is
not reimplemented. Use it instead.
Note that when using the variant that returns a (NSArray *) with a selector
that usually returns an object but returns a nil in a particular case
a NSNull object is stored in the resulting array.
What more is available?
OHHelper
contains some macros.
(min,max,min3,max3,fitRange <- on opened and closed intervals)
OHTuple
is like (a,b) but not type save ;) - it just stores two objects that can be
retrieved by calling 'fst' or 'snd'.
OHFunction
lets you store a Methode call in an object for later execution.
OHFunctionCatImageGetter
lets you store a Method that will load an image at a later time.
OHLazyObject
Initialized with an OHFunction it will create an object when it is requested
and cache it for later use. On a memory warning the cache is cleared.
OHLazyMutableArray
Using LazyObjects internally it just behaves like a normal array except
that you initialize it with OHFunctions. Upon request of an object the
object is generated behind the scenes. On a memory warning the object gets
released again - so if you have the object retained elsewhere, in order to
free up the memory, release it there too (if possible).
OHVector
I dont know why but Apple has forgotten to add simple operations on vectors
(CGPoint) ... or I was just unable to find them. Here there are a few.
Please have more FUN with Objective-C!