Skip to content

Commit 5de2228

Browse files
committed
Update 2. Leaving the monad.md
1 parent e2ce0f6 commit 5de2228

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

Part 3 - Taming the sequence/2. Leaving the monad.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# Leaving the monad
22

3-
A monad is an abstract concept from functional programming that is unfamiliar to most programmers. It is beyond the scope of this guide to about teach monads in general. In www.introtorx.com we find a short definition:
3+
A [monad] (https://en.wikipedia.org/wiki/Monad_%28functional_programming%29) is an abstract concept from functional programming that is unfamiliar to most programmers. It is beyond the scope of this guide teaching monads. In www.introtorx.com we find a short definition:
44
> Monads are a kind of abstract data type constructor that encapsulate program logic instead of data in the domain model.
55
6-
Monads are of interest to us, because Rx, and more specifically the observable, is a monad. Rx code declares what needs to be done but the actual processing happens not when Rx statements are executed, but rather when values are emitted. Readers may find it interesting to read more about monads in general. For this guide, when refering to monads the reader only needs to think about the observable.
6+
Monads are of interest to us, because the observable is a monad. Rx code declares what needs to be done but the actual processing happens not when Rx statements are executed, but rather when values are emitted. Readers may find it interesting to read more about monads in general. For this guide, when refering to monads the reader only needs to think about the observable.
77

88
## Why leave the monad
99

10-
There are two main reasons one may want to leave the monad. The first reason is that a new Rx developer will still be more comfortable in more traditional paradigms. Doing parts of the computation in a different paradigm may enable you to get some parts working, while you're still figuring out how to do things in Rx. Another reason to leave the monad is to interact with components and libraries that weren't designed with Rx in mind. When refactoring existing code into Rx, it may be useful to have Rx behave in a blocking way.
10+
There are two main reasons one may want to leave the monad. The first reason is that a new Rx developer will still be more comfortable in more traditional paradigms. Doing parts of the computation in a different paradigm may enable you to get some parts working, while you're still figuring out how to do things in Rx. The second reason is that we usually interact with components and libraries that weren't designed with Rx in mind. When refactoring existing code into Rx, it may be useful to have Rx behave in a blocking way.
1111

1212
## BlockingObservable
1313

@@ -25,7 +25,7 @@ public static <T> BlockingObservable<T> from(Observable<? extends T> o)
2525

2626
### forEach
2727

28-
`Observable` has a method called `foreEach`. `forEach` is defined as an alias to `subscribe`, with the main difference being that it doesn't return a `Subscription`.
28+
`Observable` has a method called `forEach`. `forEach` is defined as an alias to `subscribe`, with the main difference being that it doesn't return a `Subscription`.
2929

3030
Consider this example
3131

@@ -49,7 +49,7 @@ Subscribed
4949

5050
The code here behaves like `subscribe` would. First you register an observer (no overload for `forEach` accepts `Observer`, but the semantics are the same). Execution then proceeds to print "Subscribed" and exits our snippet. As values are emitted (the first one with a 100ms delay), they are passed to our observer for processing.
5151

52-
`BlockingObservable` doesn't have a `subscribe` function, but it has `forEach`. Lets see the same example with `BLockingObservable`
52+
`BlockingObservable` doesn't have a `subscribe` function, but it has `forEach`. Let's see the same example with `BLockingObservable`
5353

5454
```java
5555
Observable<Long> values = Observable.interval(100, TimeUnit.MILLISECONDS);
@@ -70,7 +70,7 @@ System.out.println("Subscribed");
7070
Subscribed
7171
```
7272

73-
We see here that the call to `forEach` blocked until the observable completed. Another difference is that there can be no handlers for `onError` and `onCompleted`. `onCompleted` is a given if the execution continues, while exceptions will be thrown into the runtime to be caught:
73+
We see here that the call to `forEach` blocked until the observable completed. Another difference is that there can be no handlers for `onError` and `onCompleted`. `onCompleted` is a given if the execution completes, while exceptions will be thrown into the runtime to be caught:
7474

7575
```java
7676
Observable<Long> values = Observable.error(new Exception("Oops"));

0 commit comments

Comments
 (0)