working with mutable time- varying values. Declarative – is about “what” not “how” to accomplish. Unlike imperative approach, system takes care of “how”. FRP
for (NSUInteger index = 0; index < words.count; index++) { NSString *word = words[index]; // do stuff } What NSArray *words = ...; for (NSString *word in words) { // do stuff }
program state behaves differently depending on program state Mathematical function result of a function depends only on the arguments easier to understand and predict the behavior of a program
objects to be notified of changes to specified properties of other objects. not easy to use lots of unused parameters hard to maintain multithreading no block-based API
forKeyPath:@"hunger" options:NSKeyValueObservingOptionNew context:NULL]; // . . . [dog removeObserver:me forKeyPath:@"hunger"]; // Observer class of ‘me’ object - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { // . . . } should remember pointer to observer object should remember key path should care of removing observer should implement observeValueForKeyPath... method in observer lots of if else statements because of keyPath
general you also can: combine operations together or derive state react on UI controls events and everything that changes over time operate with timers easily maintain networking operations operations can be chained sequently instead of nesting blocks
subscribers: next – provides a new value from the stream. error – indicates that an error occurred before the signal could finish. completed – indicates that the signal finished successfully, and that no more values will be added to the stream.
series of values. Streams are Haskell monads. Signal (RACSignal) – push-driven stream, represents data that will be delivered in the future. Sequence (RACSequence) – pull-driven stream that behaves more like a collection (NSArray, etc)
of this project: http:/ /github.com/ReactiveCocoa/ ReactiveCocoa Should take a look at Elm and meet some FRP theory http:/ /elm-lang.org/ Lookup brief material on Wikipedia or some blogs