| 
									
										
										
										
											2016-03-20 11:50:21 +03:00
										 |  |  | --- | 
					
						
							|  |  |  | layout: pattern | 
					
						
							|  |  |  | title: Monad | 
					
						
							|  |  |  | folder: monad | 
					
						
							|  |  |  | permalink: /patterns/monad/ | 
					
						
							| 
									
										
										
										
											2019-12-13 21:09:28 +02:00
										 |  |  | categories: Functional | 
					
						
							| 
									
										
										
										
											2016-03-20 11:50:21 +03:00
										 |  |  | tags: | 
					
						
							| 
									
										
										
										
											2019-12-13 21:09:28 +02:00
										 |  |  |  - Reactive | 
					
						
							| 
									
										
										
										
											2016-03-20 11:50:21 +03:00
										 |  |  | --- | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ## Intent
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Monad pattern based on monad from linear algebra represents the way of chaining operations | 
					
						
							|  |  |  | together step by step. Binding functions can be described as passing one's output to another's input | 
					
						
							|  |  |  | basing on the 'same type' contract. Formally, monad consists of a type constructor M and two | 
					
						
							|  |  |  | operations: | 
					
						
							|  |  |  | bind - that takes monadic object and a function from plain object to monadic value and returns monadic value | 
					
						
							|  |  |  | return - that takes plain type object and returns this object wrapped in a monadic value. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-07 20:01:13 +02:00
										 |  |  | ## Class diagram
 | 
					
						
							| 
									
										
										
										
											2016-03-20 11:50:21 +03:00
										 |  |  |  | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ## Applicability
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Use the Monad in any of the following situations | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-13 21:09:28 +02:00
										 |  |  | * When you want to chain operations easily | 
					
						
							|  |  |  | * When you want to apply each function regardless of the result of any of them | 
					
						
							| 
									
										
										
										
											2016-03-20 11:50:21 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | ## Credits
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | * [Design Pattern Reloaded by Remi Forax](https://youtu.be/-k2X7guaArU) | 
					
						
							|  |  |  | * [Brian Beckman: Don't fear the Monad](https://channel9.msdn.com/Shows/Going+Deep/Brian-Beckman-Dont-fear-the-Monads) | 
					
						
							| 
									
										
										
										
											2019-12-07 20:01:13 +02:00
										 |  |  | * [Monad on Wikipedia](https://en.wikipedia.org/wiki/Monad_(functional_programming)) |