Check out a free preview of the full Hardcore Functional Programming in JavaScript course:
The "Either/IO Exercise 1" Lesson is part of the full, Hardcore Functional Programming in JavaScript course featured in this preview video. Here's what you'd learn in this lesson:

In this exercise, write a function that uses checkActive() and showWelcome() to grant access or return an error. Brian gives the audience a few minutes to start working on this exercise before giving the solution. - Problem: http://jsbin.com/zegat - Solution: http://jsbin.com/tosusijoje

Get Unlimited Access Now

Transcript from the "Either/IO Exercise 1" Lesson

[00:00:00]
>> [MUSIC]

[00:00:04]
>> Brian Lonsdorf: Again, I'm gonna go ahead and define this log. I wonder if this'll, I think you guys will probably all, you know what, forget it, it's not gonna be easy to log. Well, maybe it will be. Who knows, let's try it.
>> Brian Lonsdorf: Maybe you guys will get this change, maybe you won't, I don't know, JS Bin mysteries.

[00:00:40]
>> Brian Lonsdorf: I didn't say it earlier, but I'll say it now. Either is good, if you put it inside a future, when you're doing asynchronous stuff. We'll talk about future soon, but right now, let's think of it, futures wrap up that too. So, let's just worry about synchronous versions of this when you're doing, dealing with either right now.

[00:01:06]
>> Brian Lonsdorf: [LAUGH]
>> Brian Lonsdorf: Is anybody having trouble understanding any of these? This first one, you just wanna write ex1.
>> Brian Lonsdorf: It's exactly what we've been doing with the other ones, just with different types.
>> Speaker 2: [INAUDIBLE]
>> Brian Lonsdorf: Yeah, and everybody has their own JS Bin URL, once you start editing it.

[00:02:16] So if you have problems, we'll just put it up here and play with it.
>> Speaker 2: Might be even better, yeah.
>> Brian Lonsdorf: Yeah. That's a really good idea, actually [LAUGH]. Chat or raise a hand if you have problems. We'll drop it on the screen up here and walk, work with you on it.

[00:02:35] And hundreds of people will love you for it. Hundreds [LAUGH], thousands. Okay, so we're just gonna go through these quickly, cuz we're running out of time, and the main, it's the same stuff. Okay, so, and I know it might not look like the same stuff, but let's just talk about it for a second.

[00:02:55] So what we wanna do is, checkActive and showwelcome, if they're active. So, checkActive is gonna return us a right or a left, depending on if they're active. So, Gary's not active, but to reset is active, down here in the tests. So what I'm gonna do is, basically, let's see, we're gonna checkActive, we'll compose that with showwelcome.

[00:03:19] But, by golly, checkActive returns a right or a left, we can't just call showwelcome, which expects a user. So we have to map over that. And at this point, you should be like, that's the same thing [LAUGH] that we've been doing to run that one. So one's good.

[00:03:38] And it runs for Teresa, but not for Gary, and if you want me to prove that, I can do that and, you know, and you say, no, you expected this, but you put it either. So it's good to fail these tests just to make sure you're on the right track.