 Good morning. Can I eat foji ice food? Yeah, that makes me alive. I think most of you got tired seeing this banana for a pretty long time. All I asked was for a banana, right? And what I got was a gorilla holding the banana. Not only that. I got the entire forest. This is what Joe Armstrong, the father of Alang said about object-oriented programming. I'm not going to talk about object-oriented programming and why it's bad or if it's working for you well and good. But today I'm here to talk about going functional with JavaScript. But why JavaScript? As you all know, JavaScript is already a multi-paradigm programming language. It also supports a few functional concepts like functions as first-class citizens, closures. But there are more things that we can do with it. And let's see how we can go functional with JavaScript as we proceed. Functional programming is a hot topic, right? I need some conversation here. Very hard. Not really. 1930. Alang O'Church, 1930. This man, when people were giving talks on set theories and making axioms, this man said I'll write functions. And we called it lambda. And that's what lambda calculus. See, there was a proposal for lambda calculus. And anybody know who this is? John McCarthy. Yeah. The father of Lisp. He said you're doing it completely wrong. And he wrote Lisp which implemented the lambda calculus which was proposed in 1930. This was in 1970s. And today it's hot. What is functional programming language? Well, there is no single definition. It's like this philosophy of whether the glass is half empty or half full. You would rather say take the glass and drink the water. So there's no single definition. But let's try to define it. Say functional programming is all about, let's take the contrast of what object oriented programming was. Like you see an object, you feel it and is an object, has a glass and you derive and what not out of it. So something which can be feel and felt like you can see it in your real life is an object. So there was this object orientation. Another thing which is related to process. Say you have to, you have a file which you read or you have a file stream which you process it and you get another steam and then you write it to a file. Some process oriented thing is normally could be a functional in nature. Why functional programming language? Obviously you can write cleaner code who doesn't want to write a cleaner code here. You can write a cleaner modular code which could be composable, testable. And above all of this something like it's mathematically correct. You can see your code and prove it mathematically even before executing it. Even at the design phase when you're designing your product or where you have your architecture. If you go the functional way you can prove it mathematically whether it's right or wrong. You can see where it could fail or where it could succeed and even before implementing it. That's a huge success. It must be sleepy. So mathematical correctness. So if you have made the projector go functional or if the projector software was written functionally it would be easier to debug. So you could just go ahead and fix the small function which was causing this issue. I bet it would be an object oriented. I'm not against it but yeah. So let's get some of the jargons. That's there you are speaking to her. You must get your jargons right. So let's get some functional jargons so that it will be easier when we do the live coding part. This must be pretty familiar for most of you but I just want to run through if you are not. Arity. Arity is nothing but the number of arguments you pass to the function. Here I have a small function and it takes two arguments and hence it's additives too. Then we have higher order functions. Higher order functions are nothing but functions which can receive functions and functions which can return functions. So here is a greet function which takes in name and returns a function. And on passing higher order to it it executes the function saying hello h of higher order functions. Then we have curry if you can see the small guy in picture it's Haskell curry. The currying name is from Haskell. So we have the getColor function here which takes RGBA as in red, green, blue and alpha. And the function is called Masala which takes in RGBA as in this ES6 notation of arrow functions where the first function returns another function and the second function returns the other function and so on. So what basically currying is if you curry a function the function will end up returning a function that is waiting for other parameters as in here we have RGBA. So the Masala function returns r which is expecting g which is expecting b which is expecting a. But the getColor function was just RGBA the arity was 4. So the whole idea is reducing the arity to a single arity right that's currying. So how many of you have heard currying and tried here? So you must be thinking isn't this partial application right? So we need to get our definition right. Partial application is about applying partially the number of arguments that the function take. So for example here some takes a b and we are doing a plus b. When we partially apply it we are binding with 40. So when I do partial of 2 I get 42. The difference between partial application and currying is the key thing is in currying the function reduces to another function which accepts a single arity and then with partial application it need not be returning a function that accepts a single argument again. It's just partially applying you could partially if it says we had other math function we had n number of arguments you could just partially apply n minus whatever you want. But in currying it should always be 1 until you reach n. Is it clear if you have any doubts you could just ask me right away like if it's not clear I want some conversation again please guys alright. So this was me yeah can I switch to my terminal here and show it to them or I am just hitting Babel that was it that the question was to explain what arrow function is what that single line actually is. So let's say the same same example is it too small alright. So this is what we were doing right. So if you see at the right Babel is translating the e s x square to e s y. So something like sum which is equal to a comma b returns a plus b would be would get in e s phi would be a simple function. So this is more of an abuse of an arrow function I would say because arrow function is meant for lexical binding. I am not talking about lexical binding right now but it's meant for that. Other thing key thing you could keep in mind is if your arrow function is just accepting one argument you need not need those parenthesis you can just and you need not read the you need not need the written statement as well. So I say say add one equals a and takes an argument and adds one to it. Then this thing on the left gets translated to right. That's how we would normally write or most of them would write it today right. But if you are into e s x already it would be like this. Thanks for the question center. The RGB thing and this here is template literals. Is that okay you would still see it right? Yeah so this is arrow functions returning other arrow functions. As you could see r itself is a function. Then whatever follows the arrow is again a function. So on and so forth. So if you see it right RGBA. RGBA the first argument that it takes in is r. And then it returns a function alright which is expecting g. And then again it returns a function which is expecting b. And then again it returns a function which is expecting a. So finally it returns r plus gba. r divided by I missed the dollar there. So dollar there expands into the expression in template literals right. So I have the RGBA so it finally concats RGBA and returns. Is it clear? Say yes or no guys say at least say one or zero. So partial applications and then this was me tweeting some days back like. Ayurveda and functionally programming have something very much in similar. They have no side effects that's their motto. At least that should have been the motto. So what are side effects? So console.log io side effect. Console.log itself is a side effect. So what is a side effect? We all know what an effect is a cause and effect. But this is a side effect what you see on the projector now. So the side effect is exactly that. So a program that is manipulating something outside its scope. So if console.log is printing something to the console right. So it is changing the state of the console. So console.logs whatever the function is doing inside is changing the behavior outside. That itself is a side effect. So it could be one thing like how do I even code without having side effects. So I need to mention Haskell here where they have a very good paradigm called the io. Where if there is a function which has a side effect they would mention it in the signature saying hey this has a side effect. So writing the code which has absolutely no side effect is very very hard and it's not very practical especially in JavaScript. So we need to take care of having less as much as less number of side effects that our program can have. That is because it's easier to debug when you see the code you could predict what it's doing and the mathematical correctness of it. So this is purity the pure functions. Any function that doesn't have a side effect is a pure function. So if you can see here I have a greet variable which says io and then I am doing an uppercase on it and still greet remains the same. The uppercase function isn't really modifying anything else but it's creating a new string and returning the uppercase of that string because greet is still small case io. This is a pure function. So pure functions don't have side effects. So idempotency you would have all heard this like any function say for example let's not worry about the math apps. Let's say you have a sine x function and you pass sine 90 to it. You got a value 1, sine 91. So no matter how many times you call sine 90 you still get 1. So that is an idempotent function. I hope my bank account was like that. I go to the ATM and I swipe a lack of rupee. Every time I swipe I get 1 lakh no matter what. That doesn't really happen. So that is not an idempotent function but this is an idempotent function. I know it's pretty early for some of them probably some of them used to get up now. I don't want to bother you with a lot of theory and concept but trust me when it gets to the live coding part it will be fine. So the point three there's a point in point three. What point three is if you can see the two function calls can you see some similarity or something strange in this? If anybody could say about it. All right. If you see parse float and parse int are two functions which are expecting the numbers right. But I am mapping over them but I am not really passing those numbers to parse int or parse float but still we get the parsed int and parse float values right. So that is the point three part of it. Point three in the sense your code doesn't really bother about parameters to parse to the function right. So what parameters you are passing you are not really specifying it. That's the point three part of it. It's pretty hard to get point three but once you get the point three concept of functional programming it will be fun. So the whole idea here is to use JavaScript and going functional with JavaScript but if you get the you finally have to get the functional way of thinking right. So to that you need to understand bit of jargon and bit of math theory, bit of category theory and everything summited together will make you help think functional no matter in what programming language you are coding. Referential transparency. So what is referential transparency? Say you have a code which has something like idli and sambar and there's one more function says which is says idli and sambar. So it finally returns invocation of idli and sambar. So for my friends who are not from India I would definitely suggest you to try idli and sambar. So that's one of the ancient days of India and it's free and open. There's no copyright. We don't know who really made idli and sambar first. So coming to referential transparency. So if your code has something like this any part in your code where there's a call for idli sambar you could go ahead and replace it with idli sambar string. So finally referential transparency means that part of the code which can be replaced by its value. What if I say to you that functions are values, right? In JavaScript that's what in functional programming all functions are values and something that function that could be replaced by its value is referential transparency. Lazy evaluation. This is the closest we can get on lazy evaluation with JavaScript. This is using the ES6 generators. The star there is what makes the function a generator. I'm not going to go in depth of ES6 generator. There might be talks ahead which really talks about what ES6 is and how to go about it. So there is this random function which random, rather a random generator function which gives you an iterator on invocation and doing a next on it will give you a random number. So what's the laziness part of it? So say let me give an example. Say you want to generate numbers from 0 to n where n is a billion, right? So if your code is generating 0 to n where n is a billion in a loop, it would take a long time and it would be lazy. It would not be lazy. It will be slow. Laziness is the part where say you have 0 to billion but you ask your program to give me 0 to 5. Then it will generate 0 to 5 and give it to you rather than having a billion in it and then giving only 5 out of it. So you get the point, right? Yeah. You have a question there? So lazy evaluation is which generator this is the closest we can get but the thing is two things. There are programming languages which are purely functional and there are programming languages which helps you to implement the functional style. JavaScript is on the left. So it kind of helps you to implement the functional style. With purely functional programming languages, every function will be carried by in itself and the laziness is inbuilt. Tail recursion is one of that ES6 proposal that got in. Tail recursion is possible. Say you might have read recursion with the Fibonacci series, right? Most of us would have. So if you give a very huge number to your Fibonacci sequence, you would get a maximum call style. Your stack would grow up and it would bomb. So with tail recursion that would not really happen. With tail recursion what happens is the code gets smart enough to be a little busy and take care of that recursive call so that it doesn't really bomb up. Right? Some more. We have compose where composition of functions say here we have a compose function which takes two function f and g and returns one more function which is expecting the value x. Finally it returns composition of function f with composition of function g. So if you have say if you have compose method which says compose x with y, it's like you can assume that it's evaluating from right to left. So it executes y first whatever the value gets, gets applied to x and finally you get the result. So this is composition and this will be very useful to write modular programs. That's seven points what I was speaking about. Immutability. So we saw an example of string there where u, great equals u and you did uppercase right. The string was really not mutated, mutated in the, in the sense changing. So immutability is one such concept where you have to take care of not to change any parameters you receive or not to change any variables. This helps in the mathematical correction, correctness of the part where you are not mutating anything and statelessness. This is related to the first slide where I, where I talk about bananas like gorillas and the entire forest, right. That is all the states that, that comes with the object. You just ask for an object banana but you got the entire state like is yellow, is vegetable, can I peel, has peel like all these methods and all the states and it's very huge. So when you're writing, when you're thinking functionally you have to see to reduce the state as much as possible and if you have state and you have to be very careful like what react is doing with their states is a very good example of thinking functional and yet still having the states. So having a state, you have a state which is shared and it's mutable then it's hell. So if you have a shared state, you have to see to that it's immutable. So these two are connected. Yeah, I know. Talk is cheap, show me the code. All right, even before I start this I want to talk about small library that I'm using. Is it big enough? Ramda. So how many of you have tried Ramda here before? A couple of them, nice. So Ramda is one such library which really helps us to go functional with JavaScript. Why did I choose Ramda? There are a few things. The most important thing is every function in Ramda is curried. The way the code is implemented is very functional and you get to see when I show you few examples. I would definitely suggest you to have a look at Ramda. Yes, there is the philosophy behind Ramda and there's a wonderful post on philosophy behind Ramda and I would definitely suggest you to see this video on k underscore you're doing it wrong by Dr. Boolean. That's really good. Is it big enough? All right. So this is a Ramda rappel on the web. So let me start with small examples and let's proceed with it and see how we could think functional with some live coding. So say you have an array of numbers. So the task here is to just add one to each of them and return the resultant array. How to do it with an imperative programming language like imperative programming paradigm rather. So you would have a results array. Then you have a follow-up. That's nothing to do with the follow-up. And I think this is the right time to copy case code. No, not really. So you have a variable with an index that starts with 0 and probably you could cache the length as well. I'm not here right now. And what you would do is result dot, oh sh, nums of i. You could either do the plus plus but there's a lot of philosophy behind that as well. And result I get 11, 21, 31, 41. This is how most of us would do with follow-up, right? So if you have used, if you have read the MDN docs for all the array methods, you'll probably notice I would opt map and I would go ahead and do it with map. So with map, this is again the arrow function there. So you don't need the results at all. You take the number and map it over n and return n plus 1. I still get that. So you see the point there. We reduced having a variable called result and that was getting mutated. So we reduced mutation, we reduced the variable. And then we were looping over creating one more variable there and calculating the length. We reduced all of them. We reduced the entire thing to one single line with a map function. So if we say map and we just take each of them and add 1 to it and map finally returns an array for us. Now talking about Ramda, the same map if I do it with Ramda, it would be this. Can you see the difference here? So the difference is in the thing above Ramda, we have the callback at the last. So we have numbers dot map, then the callback. But in Ramda, we have the function first and the number next. So you might be thinking what's the big deal about having the function first and the numbers next. I will just make it clear to you in a second. Suppose I do this and call it add 1. So this is function again. And I could just say add 1 of nums. You see that? We have completely decoupled the add 1 which is a function which doesn't even bother about what it's adding 1 to. It's a map function which is taking a function first and the argument next. So add 1 is like a create function which is waiting for its arguments. Because of this, composability is very much easy. That's why I have choose Ramda. So far it's clear. So we started with numbers. All we had to do is add 1 to it. We tried with imperative coding where we looped over it and added 1 to it and pushed to the result. And then we did use map function which JavaScript gives by native. And then we use Ramda. And we are clear now with why Ramda and why it's useful for composability in the functional way of coding. Let's go to the next example. Where I have the filter example. Very much simple. We could reproduce the same thing again with having numbers array and then doing numbers dot filter and all. So in this example we have array 10, 20, 30, 300, 33 and 1. And what filter basically does is it takes for the condition where we are saying x greater than 10 on this list. So you want to filter a list which has all the, you want to filter the list and get a resultant array which has only the numbers which are greater than 10. In our case we got 20, 133. So this is a very simple example. But most of us would be doing it in our day-to-day life of coding. You have a huge JSON with you. You pass it. Then you have to filter out few things. So this is how you could use filter to filter out only those things which you need based on the condition. The condition there is x greater than 10. Then you have reduce. This is one of my favorite functions. So what reduce basically does is it takes a function and it takes an accumulator and then it takes a list and it operates, it applies that function on the list over the accumulator. So if you see this example it will be a bit clear. So what I am doing is adding the list. So you have a list and you have to add all the numbers. So the accumulator starts with 0 and then you add the first number that is 10 with 0. So you get 10 and then you add 20 with 10 you get 30 and then you add 30 with 30 you get 60 and then you add 60 with 40 you get 100. So that is where the accumulator and the number goes in. If this is a bit confusing you can call it n. So it is 100. Now if you see I am starting the accumulator with 0 because I want to add all of them. So suppose I want to say I want to add 100 to each of them and then add all of them I could just change the accumulator. So I got 200 or even 10, 110 right. And the fun part with accumulator is accumulator need not be just a number it can be an object it can be an array. So you can implement your reduce and filter or you can implement your map and filter with reduce. Then you have a similar thing called reduce right where it is very much similar to reduce but it in reduce what is happening is we started from 10, 20, 30 right that is from left to right but this starts from right to left. If you see the strings which says B, A, C, K, W, R, D S backwards it started from right to left and concatenated them and we got backwards string. That is reduce right. Trans reduce is one of Ramda's function but it is a functional concept as a whole. But let us see a small example. The composed part what I was saying the f of g remember that function which takes a function and returns a function calling the function applying it I know it is lot of jargons and multiple of words but the code makes it clear. So what we are doing in compose is r.prop will probably is picking up the price from the purchases right. So compose happens from right to left. So you pick up the price and default it to 0. So it is price or 0 either you have the price or it is 0. What trans reduce basically does is it acts upon the purchases starting with 0 and adds all of them and we are mapping with price or 0. Why you are mapping with price of 0 is in this purchases if you notice there is not a price which is a cow. But if you have written this in an imperative style it would have bomb saying that it cannot add cow to a number if or rather it would add cow to a number and you will end up with a string having 30, 0, cow, 10, 6 right. But here it would not really bomb that way and the result is 46. What is happening there is again in trans reduce it acts on the purchases and it starts with 0 adds all of the values and maps over price of 0 because if it is not a price then we would get 0 here carrying. So here is one more example of curried function we have ABC and we are returning A plus B into C rather this would also work you do not need the parenthesis just for the readability. So if you do 2, 3 we would end up with one more function if you see here we have a function so it is like 2 plus 3 it is waiting for C now you will pass in C you get the result. So this helps in a composability and why carrying matters is when you have a function which is expecting a number of functions and you have at the current instance you have only three parameters to pass to it or in this case we have only two parameters to pass to it we could pass to it and get a get a get another function which is expecting the last argument and we could use that as a generic function throughout our code anywhere compose yeah I think by now compose you should be clear compose will always act from right to left here we have numbers 2, 3, 4, 5 we are filtering it out the filter we saw in the example we are filtering it out with x greater than 4 so we would get 5 and then we are mapping over it and multiplying it with itself I think like squaring it so you get 25 that is the compose part there is one more function called pipe. So what pipe basically does is I have been saying that compose you can think of it as acting from right to left right pipe is like your unique pipe you could have done an LS iPhone L and pipe with WC iPhone C or to know how many lines you have right or L so you know that pipe character what we have so pipe function works similar to your pipe character here the function on the left is applied first and whatever result is get passed to the right one and whatever result finally comes out is the final result. So same function as compose we are filtering with x greater than 4 and mapping in compose but here we map and then filter so here we are getting 25 in the previous one we were getting just 25 clear exactly so he said basically it is L to R and R to L processing that is an easy way to remember but I normally go with pipe as in the unix pipe where it happens from left to right all right let us go back to the slides again how would I am doing at the time talk was talk is sheep and show me the code okay let us talk about category theory some more theory and Sheldon is smelling bullshit there all right I want to talk about some basic math some 56 grade math again because what happened is we were normally getting to programming and think hey programming does not really involve the math theorems and axioms that I had learnt but not really let us just quickly refresh you of the math theory the math fundamental rather we have associative law where idly sambar into chutney is nothing but idly plus sambar into chutney and then we have commutative law where idly plus chutney is chutney plus idly and then we have identity that all our milkman knows this that milk plus water is more milk is milk again and we have distributive where you could mix your milk with sugar and chocolate adding sugar and chocolate together and adding milk to it or mixing sugar with milk and then mixing chocolate and then both together it is the same thing was it very fast or you want to just I will remember your math so category category is just a collection of same type in javascript we could say an array of integers is a category in itself category in one slide so there is the satoid anything which is a satoid implements reflective symmetric and transitive laws so you could say A equals A is reflective and A equals B equals B equals A that is symmetric and transitive so anything that is a satoid implement these three laws and semi group kind of implements associative law and concat method and there is something called as monoid which implements right identity left identity and an empty method you could see on it is basically implementing the concat from semi group A concat, B concat C is equivalent to A concat of B concat of C that is what I was talking about the milk and the chocolate thing is the same semi group and then you have monoid which implements the right identity, left identity and the empty method in it then we have functor, functor is any anything that has map in it so your array itself is a functor so anything that is mappable is basically functor which implements identity and composition and apply basically is a functor but which has which also implements a composition in a way that we saw that RGB example right similar to that but here we have also have this AP method that gets implemented in it then we have applicative applicative has identity homomorphism and the interchange you might be thinking about what homomorphism is it is very easy to guess right homo is like single and morph is to modify so it kind of operates on only one kind of category and modifies it and then we have chain if you have been using loadash or underscore you would have been a lot of doing chain function right like chaining of things this is one of the anything that implements the chain will also have associativity in it so you might be wondering why is he talking lot so much of theory of math all this semi group monoid, applicative, functor what what's all this so all this things is needed for you to understand what a monod monad is so a monad is just a monoid in the category of endofunctors that's a mouthful but yeah what's the problem the professor has but if you want to understand what a monad is you should get all this concepts of semi group applicative, functor and whatever I spoke about so so monad basically implements the chain with left identity and the right identity the fun part with monad is if a person really understands monad he can't really explain it to anybody so if I failed to explain what a monad is that means I've got what monad is all right so this is what I talked right now was known as the fantasy land spec so what fantasy land spec is suppose you want to write your own functional programming language you go and implement that spec so that spec I tried to boil down in the final image here I have a semi group which has concat that's what I was talking about if it is a semi group which it have a concat in it and of course the loss which I mentioned and then we have the monoid which has concat and empty in it and then we have the functor which is map and apply which has map and apply and so on I didn't mention about foldable and transformable that's nothing but your reduce and lift so that's the fantasy land spec in one image that was too much of theory isn't it like lot of category theory so this you might be wondering like where would the category theory be useful where exactly the term monoid will be useful there's an argument that people say jQuery is a monad and some set of people say jQuery is not a monad so you could go and read those articles where people try to prove that jQuery is a monad so here is an example called a maybe monad so the idea of functional programming is to reduce statements into functions rather what we would be used to do is if there is something which is very repetitive we'll probably boil down into a function so but in functional programming it's about say you have a for loop and you have an if and else and that was a bell ringing like the school is gonna end kind of thing and then you have you have an if and else condition and a try and catch thing the whole branching statement and the whole statements gets converted to a function in a functional programming language rather than repeated statements getting into a function right this is an example of a maybe monad where what maybe just is like it's just or nothing as in I'll try to give an example as I go further like when we have a maybe monad which says maybe I might get a string or I might get an L I might get an integer I don't know just try to do this operation this kind of things we really do right we do this null check if x is not equal to null then do this then again y is not equal to null then do this this kind of an conditional check is normally there in our functions right so with maybe you can say maybe I will get a string if I get a string then go ahead and do this operation if not just return null so you reduce whole branching statements and the whole conditional statement into a simple function that would take care of all your exceptions and returning the right values and lenses lenses is one such concept say you have your huge json I was talking about and you want to get us get and set normally what we do with objects is either you get or you set or you see whether that value exists or not right so lenses is one such concept which helps you to set view and run a function over a particular particular attribute of a function say you have an object which has a person or you have a person object which has a name say hey month and then age and then blah blah blah so many other attributes so you want to just modify the age thing so you would create a lens on the object for age and you could set the value to whatever value you want or you could view whether what is the value of the age or you could run a function on over it so lenses is also one of the monad and promise of course most of you would have heard what promises are promises also is a monad so without being aware we have already been using the concept of monads but it is very much important to understand what a monad is and to understand what a monad is you have to understand endofunctors, monoids and semi-group and setoids and functors and all the things I mentioned that would really help you to go to the next level in the functional way of thinking this is list of functional programming libraries this is one of my friends who has collected it it is on github I will share with you the link and I am also contributing to this list in this list there is loadash and loadash fp loadash fp is this new library that loadash community has got influenced by ramda I would say to have an loadash fp that fp has in functional programming which also has auto-curring and which also takes functions as the first parameter like ramda does see that library called 101 that is also from me and my friends where we have one liners one liners is kind of influenced by 101 and one liners is that library which me and my friends have done which have es6 one liners which are all functional you have map, reduce and whatever speaking about like pick and prop all of them and it is just defined in one line so you could just go to github and look for one liners and fpdom is also an effort from me and my friends on the idea was to make DOM functional so you could do a document.query selector in a more functional way and all the document related and DOM related functions in a functional paradigm so the helper function for fpdom was fpjs so I would suggest you to go and look into these libraries I have two more minutes so I will probably get into the questions and if you could see that image from the movie bau valley so I don't really know why Katapakil bau valley I can just answer other questions I will try to thanks for the talk I have a question what would we trade those between choosing one of these libraries which you mentioned versus a pure functional language like closure script so that is a very good question so the question was what is the tradeoff between using one of the libraries which you mentioned versus something which is purely functional the tradeoff is one thing is all the functions they are in a purey function programming like Haskell already gives you the maybe monad implemented in the GSCI itself and the concept of currying the auto-curring is done all the functions are auto-curried by itself in default and then we have lazy evaluations and things like all these functional paradigms are already implemented where minimal in the shell for you but if you are using functions or the libraries like this the tradeoff would be you have to first thing is you have to have this as a dependency for your project and the second thing is not every functional paradigm is implemented in it for example what about Ramda I was talking about doesn't have the maybe monad so if you want to maybe you have to go is Ramda with the fantasy land spec so the tradeoff would be having those dependencies but the fun part is you could still get a bit more functional thank you hi great talk by the way so I just realized yeah I just realized you talked a lot about mathematical proving using Haskell and you just quite a bit about it I wanted to ask you about how realistically possible it is to actually implement it for example I would argue that if I want to just actually write a proof lemma that I need to implement a red black tree a very small portion I need to prove it through my code writing a proof theorem right so it will be much easier or less time consuming than Haskell to write it in CoQ CoQ or maybe in OCaml right yeah in Haskell because it's like first non-terminating right so that might prove some problems like what's your thought on that yeah that's a good question but whatever programming languages you mentioned are purely functional yes they are specifically used for proofing that's what I'm adding on with that so if you consider javascript as I've been mentioning it's a multi-paradigm language so the mathematical correctness is what I would say say you have let's have a contrast of you're reading a file and you have to look for certain pass the file and look for certain strings in it and then you have to collect all these frequencies of those strings in the file compare it with an imperative programming language with the functional way of thinking it having more functions and composing it it's a very simple example as you told about the AV tree or the black tree this is even more a trivial example which gives a bit of clarity so here you have your imperative code where there are a lot of loops running over the files you're reading the file you're checking whether the file exists or not you're throwing an exception so many things to consider in a small function in a small little util rather on the other contrast when you have when you're doing it in the functional way for example the maybe monad style you have the maybe you check I have the file maybe you have the file then go ahead then read it then do a filter on it do a map and then concat it and give me the result or just give me the object do a filter and do a reduce and give me an object right so something very trivial as this when you write it in a functional way when you're designing it you could just think how okay so have this function I will probably compose it later on so let me have this function and let me have other function so all of this all are the set of functions right which you could which you could mathematically write even before you go and implement it you are damn sure that maybe will not fail because maybe will rather give you the file or it will give you null right the that that's one of the main concept why function got hot is we have a processor with multiple cores in it these days rather than having an higher frequency processor and multiple processor in itself we have a processor which has multiple cores but JavaScript being a single thread you could still if your function is composable you could pass those functions to each of the cores and then get it computed and then get the result right that's why the functional way of thinking or the functional programming is getting hot these days yeah we're going to have to wrap this talk up right here so thank you hey thank you guys it was a wonderful session