It was somewhere in the dark hills of eastern Kentucky, on this long straightaway through a valley. I feel that I must truly stress that there was nothing on that road, no houses, no farms, and certainly no coastline. That made the lighthouse even more striking when I saw it. It sat back in one of those meadows wrapped extending back into a mountain hollow. Even though the mid-afternoon sun and the floating pollen was turning everything around me gold, that meadow and that lighthouse were already bathed in shade from the mountains. I almost drove right past it, if I'm honest. It was so out of place, it was like my brain didn't recognize that it was actually there at first, and if there had been anyone else on that road, they may well have rear-ended me when I slammed my brakes, sending up dust and gravel as I skidded to a halt. It didn't even have a house attached to it, like the lighthouses I'd seen in pictures and movies. It sat alone, black and white stripes moving up its length like a barber's pole. Only the glass at the top was still above the shadows, glinting in the afternoon sun, but even as I watched, the afternoon shade inched up the length of the thing. I lied before when I said there wasn't anything else there. There was one thing, directly across the street, one of those old motels that's just a row of rooms wrapped around a parking lot.  There was something, some train of thought that made sense at the time, but I can't remember it now. I know I sat there for minutes, right in the middle of the road, looking at the lighthouse, but I can't remember. All I remember is that for some reason, stopping seemed like a good idea, and so I turned into that empty old parking lot. I half expected the place to be closed, but the neon sign buzzed red with vacancy and the door to the office opened when I pushed it. The front of the office was made up of floor to ceiling windows that led in lots of natural light and heat. It also gave a commanding view of the entrance to the parking lot, the lighthouse, and the mountains that served as the walls of a little valley. The woman that popped up from behind the counter was so ordinary looking that it actually circled back around to being almost extraordinary. I know that's strange to say, because how can ordinary also be strange, but it's one of those things where someone looks so ordinary that it crosses that line into the uncanny valley. She looked like the rough sketch of a master painter. Like there would be details filled in, wrinkles and smile lines, and moles and imperfections, but the painter just hadn't quite gotten there yet, or had consciously erased them. She wore a burgundy polo and her hair was blonde. I remember both of those things, but there wasn't much else. Even her eyes were this weird mix of blue and green with bits of brown around the iris. Her nose wasn't big or small and neither were her lips. She was remarkably unremarkable. Can I help you? She asked, setting a book down on the counter. It was old and weathered and the spine was bent like it had been read through dozens of times. I couldn't read the title because of how she'd laid it down. I'd like a room, please. She blinked like that surprised her. You want a room? Yeah, is that all right? Her brain seemed to catch up to her and she moved all at once as she said, yes, of course, I just normally it's people asking for change for the pay phone or something or I waited for her to finish the thought, but she only let it trail off or see the lighthouse. I asked. She was pulling a key from a desk drawer, a small gold little thing attached to a billet of wood with a room number on it and looked up at me confused lighthouse. She asked. Now it was my turn to blink confused. Uh, yeah, the lighthouse across the road. She looked over my shoulder out the window that faced the street. I, she opened and closed her mouth a couple times, clearly having trouble deciding on what to say. I honestly don't know what you're talking about. I looked at her, then turned around to make sure the giant lighthouse across the street hadn't moved. It hadn't. I looked at her again, trying to decide if this was a joke or not. And if so, what the punchline was, I pointed directly at it through the window right there. She leaned over to follow my finger, then looked at me and shook her head. The look on her face was quickly changing from confusion to annoyance. And I decided that rather than turn into one of those customers, I dropped the subject. I paid for my room and left her there in the hum of the air conditioner, walking down the long cracked slab of concrete until I reached my room right near the middle. Another question I had as I walked away was why I'd gotten this room in particular. My car was the only one in the parking lot, and all the windows to the others were dark. So how did she decide which room I got? It was nothing special. Truthfully, it was like most other old motels I'd seen, with an old queen bed topped by a floral patterned bedspread, a little lamp and desk in the corner, and an old porcelain sink that had been white once upon a time but was now stained yellow by age and nicotine, the place smelled of air freshener and mothballs. I only had a backpack, so I dropped it onto the floor and laid on the bed, flipping the television on. Static, I might have known. I turned it off and stared at the ceiling instead. I'd been driving for multiple days by that point, and whenever I stopped for the day, some trick of the eyes made it seem that still surfaces were moving. Even as I stared at the ceiling, it seemed to be flying away from me. The paintings on the wall were all seascapes of rocky coastlines being threatened by waves and storms. They began to catch my eye as I realized they were just a bit too nice to be hung on the wall inside a crappy motel. Of course, it wasn't unusual to have paintings in a hotel room, but these were different somehow. Too detailed and, for lack of a better word, dark. Despite the fact it was only five, and the day outside was only barely descending into the hot haze of a Kentucky evening. Looking at those paintings made the room feel almost cold. Only one had a lighthouse in it, an incredibly wide painting depicting a stormy bay with dark purple clouds overhead and a ship sinking in the center. The lighthouse sat on the right side of the painting on a steep cliff. It was the same color as the one across the street with black and white stripes, but this one had a house attached. For some reason, the artist had decided to leave the lighthouse dark. The light at the top was off, and the windows of the house were all black. The other side of the painting was mostly empty, showing only a windswept outcrop looking down on the shipwreck below. Something about that painting, or maybe that room, began to give me a splitting headache and I think I laid down. I must have, because the next thing I remember is waking up and everything being dark. The only light was moonlight or some street lamp diffusing through the sheer curtains drawn over the big window at the front of the room. The little lamp on the bedside table provided only a small yellow glow that didn't reach the cobwebbed shadows in any of the corners. I looked around the room for a moment and tried, really tried, to remember when I'd fallen asleep, but the memory simply wasn't there. I hadn't passed out since I'd made it to the bed, but that period of time was simply missing. When I peeked outside, I found two surprising things. The first was that the glow through the curtains was not, as I'd originally believed, the moon or a street lamp. In fact, as far as I could see, the light in the center of the parking lot didn't work, and I couldn't find the moon in the sky. Instead, the source of that light seemed to be the lighthouse. I say seemed to, because a thick mist had settled across the whole valley while I'd slept, and I could barely see anything of it. Besides that dull blue light growing through that sea of mist, even as I watched, though, that dull glow began to pulse with a steady throb, like a heart beginning to beat. What I noticed second was much more gruesome. As my eyes adjusted to the dark and the mist, I began to see the figures standing mutely in the parking lot and the road, watching me with eyes and open mouths that glowed. With a thin version of that same bluish light, until all the mist in the valley was colored a strange turquoise that made me shiver. I did what any normal person would do, and picked up the phone to call the police. Glancing around, quickly realized that the room didn't actually have a phone, and still they stood in the curling fog as the lighthouse pulsed overhead. I opened the door, and it was like walking into a pool house. The air was so thick and damp that it was hard to breathe, like being wrapped in a wet blanket. The night was warm, but the fog was cold, and I wished I'd had a jacket. Hello? I called. I knew they were looking at me. Those glowing eyes and mouths were facing me, and there was no one else around. Who else could they be looking at? The only other light around was that dirty orange glow of the office, and I made my way toward it. I decided I would go ask the office girl if she could see the dead people standing outside, or if that was another one of those things that seemed particular to me. My footsteps caused a strange echo under the sidewalk awning as I walked, and I could see their glowing eyes following me. The office itself was locked, but there was a night window with a little sign that read, please knock. When I did, she slid it open with a look of confused annoyance. Come back to ask about the lighthouses again. She said, I jerked a thumb toward the parking lot. No, I came to ask about the weird dead people out in the parking lot this time.  I remember having the thought that I should be more worried than I was, but I was vaguely sure this was all just a dream and I was going to wake up any minute. Even if it wasn't a dream, there was such a feeling of everything not being real that I couldn't muster up that fear. She could, though.  She said, her reaction is what broke that strange dream like blanket that had been laying over me and sent my heart into my throat. Fear is contagious and I'd caught it. So you can see them. She shook her head in disbelief.   I was hoping you'd know.  She said her voice was absolutely shaking as she looked at the mute figures once again. She unlocked the door to the office and yanked me through before slamming it closed and locking it. She slammed the window too, but pressed her cheek to the glass to stare wide eyed at the figures outside. I don't think they're coming any closer. You don't have any idea what they are.  She took several quick, shallow breaths, then swallowed the panic that I could see trying to fight its way up her throat. Okay, cops, that's what you do here. You call the cops. We're going to call the cops. She looked at me as if to make sure that was actually the correct response. I nodded, cops, cops. She repeated and pulled the phone from the receiver, punching the three numbers so hard that the phone's base scooted slightly with every touch. There was a moment's silence. Yes, this is Motel 9 on Highway 12. We need help. Now, there's these things out there. These, well, they're not things, they're people. They're just standing out in the fog staring at us. And I heard chatter through the phone. No, there's just one guest here in me. Please, please hurry, we don't know what they are and we're both really scared and just please hurry, okay? She nodded and put the phone back on the receiver. They said a car is on the way. She told me. It sounded strangely like she was trying to reassure me, but her hands were shaking and her breaths were shallow and ragged. I got a feeling that her telling me was only a way to reassure herself at this point. They didn't want to stay on the phone with you, I asked.  Tears welled up from the corners of her eyes, those multicolored eyes and she dabbed at them quickly. Why would they? I was pretty sure they were supposed to, but I didn't think that now was the time to tell her that, so I shook my head. Never mind. Now we just have to wait, she said, and slid down onto the floor behind the counter, cradling her knees in front of her. They'll be here soon. She nodded to herself. I looked out the window at the figures in the fog. I had a feeling that no matter how soon the cops could be here, it wouldn't be soon enough to matter. Still, they hadn't moved as far as I could tell, and I began to wonder what it was that they were waiting for. I don't suppose this is the part where you tell me about some old story from around here about things like this, is it? I asked. I didn't think it was likely, but the question filled the silence, and it was the silence that was frightening me. I had this feeling that I couldn't quite explain, and it told me that if that silence stretched on long enough, it would begin to hear things that I didn't want to hear. She looked up at me and shook her head. She reached up onto the desk, feeling around until her fingers grasped the book she'd left there and pulled it down, clutching it to her chest like some talisman. I pointed at the book. I don't suppose that's some kind of ghost encyclopedia, is it? She shook her head again.  It was a sound beyond fear, beyond terror or anguish that had passed through all those emotions to land its sheer hopelessness, and it wrenched at my heart. I sat down on the floor opposite her. I considered reaching out, maybe putting a hand on her arm to give her some kind of human connection or comfort, but thought better of it. Come on now. That was a joke. I told her. She whispered. The conviction with which she said it felt like a slap, and the knowledge that I very well could be living my own last night here with this girl began to earnestly sink in. Still, the knowledge that this person, this girl needed my help, if only for the next few minutes, helped me smother that panic. What's that book you're reading? I asked her. She looked up at me, and then at the book she was still cradling.  It's, uh, it's about a lighthouse. I knew if I turned and craned my neck, I'd be able to see that blinking light still floating in the fog at the top of that lighthouse. A lighthouse that I could see, and she couldn't. Lighthouse. I asked her. Yeah, that's why I was so weirded out when you came in earlier asking about that. I thought you were talking about the book or something. I shook my head. I don't even know the name of it. She furrowed her brow again like she was struggling to remember the name. She held it out to me and the title read The Sins of Amy Campbell. I gave the book back to her. I don't think I ever got your name, by the way. I'd given her mine earlier for the paperwork and the room key, but I offered it again. Mine is Tom. She was cradling the book to her chest again as she responded quietly and without looking. Macy, my name is Macy Pelbham. It's nice to meet you, Tom. I started to say something else, but that's when the moans started. I thought it was wind at first, but when it went on for a second longer than normal, I realized the truth. It wasn't just moans either, but whales and crying too that sounded impossibly far away. I could tell the moment she heard what little color remained on her face drained away. Before she could speak, though, the overhead light snapped out with the sound of glass breaking. Macy screamed, and I started as the darkness settled around us. The only lights now, the humming red neon and the mist outside glowing that pale blue silver color. She was so pale, and that neon light outlined her in red as she put her head back on her knees and started sobbing again. I thought of saying something, but before I could, I watched one of those figures from the fog walk slowly up to the window and stare in. He looked at her for a long moment before turning to me. I didn't move, and I don't think I even breathed as I waited there, watching. It was the closest I'd been to any of the figures, and what I'd taken to be dark clothes and the mist weren't actually dark, but were instead rotten rags. His might have once been an old fashioned coat with a high collar under a thick wiry beard that reached almost to the remains of his belt. Close up, his eyes still glowed with that same eerie turquoise color. Macy, I said, it turned back to look at her as she sniffed and raised her head. What? She asked. Her eyes were puffy in bloodshot. She looked to the spot I was staring at and then back again, repeating her question. What? You don't. I started, but the figure standing at the window looked back to me again and shook his head slowly. Don't what? She asked. She turned to look at the spot where the figure stood again and then back. Do you see something? Even as I watched, though, the figure turned and, like he'd forgotten what he came for, purposely ambled off back into the mist. Why can't you see the lighthouse? I asked her. The lighthouse? The one you were talking about when you got here? Yeah. Look, I thought you were messing with me when you got here. She said, wiping her eyes. I have no idea what you're talking about, though. There isn't a lighthouse here. I don't know what's going on, but I know there's not a lighthouse. I turned. Outside, the light was still blinking in the fog. I got that sense again that I'd wandered into some dream or some part of the world that wasn't quite real. A gust of wind tugged at the mist shrouding those figures again and joined the faraway sounds of the Moans. Do you hear that? She asked excitedly. I listened, but could hear nothing new over the Moans. What is it? I asked, Sirens, they're here, we're all right, we're gonna be okay. Before I could say much of anything. She jumped to her feet and pressed her face to the window. I got up much more slowly, trying to listen. I don't hear anything. I told her. She ignored me, pressing her nose to the glass as she looked back and forth frantically. Why don't they have their lights on? I can't see them. I still don't hear them. I repeated, how can you not? They sound like they're right outside. I knew the answer even then, but I didn't know what to say. Right then, the blinking light that had marked the top of the lighthouse changed suddenly to a red and blue blinking light, like a police light. There, she said, they went into the field. Come on. No, just wait for a second and we'll, but she was already running out the door. I lunged for her arm and I watched it pass right through my hands, like more of the mist floating outside. Every part of me that touched her went cold and numb, like I'd submerged it into ice cold water. She ran through the parking lot straight toward those waiting figures and that blue and red light flashing somewhere high overhead. She ran and the mist and the night both swallowed her whole, closing behind her like water. I walked out into a night that smelled of wet asphalt and grass and cedar and stood there for a moment, deciding whether to go after her or not. The moaning had stopped and to this day, I don't think I've ever experienced a silence as deep as that one. When I watched those figures all watching me, there were no bugs, no far away sounds of cars or trains, nothing at all until the screaming. I knew it was her. It wasn't even words, but just a loud, piercing, fear soaked scream that covered the valley like a blanket for those few seconds before it too receded like the tide into silence. The light blinking above the fog turned back into that blinking turquoise and then went steady again. I stood rooted to that spot for a long time, unsure what I'd seen or what I should do. I had a feeling that I couldn't call the police, not really anyway, and I didn't know what I would tell them if I did. Instead, I waited there in the night, hoping I'd think of something, but I didn't. I walked back inside and all I found was that old paperback book thrown to the floor in her hurry to be gone and I picked it up, slid it into my pocket, and walked back to my room. I drew the curtains closed and those paintings again caught my attention. In the largest, I actually noticed something I hadn't before. On the far left of the painting, on the second cliffside that I'd thought was empty, there was a small figure painted there, watching the wreckage with a tiny lantern. I wasn't sure how I'd managed to miss the detail before or why it caught my attention now, but I watched him, wondering what he must have seen and why he was put in the painting in the first place. Like before, though, the longer I watched, the more my head ached until I didn't even have the strength to peek through the curtains one last time before a dreamless and painful sleep took me. I woke up the next morning feeling like I'd been hit by a bus. The curtains were open again for some reason and bright harsh sunlight was filling the room.  When I dragged myself out of bed, I saw that I was still the only person in the place. My little car looked even smaller in that wide empty parking lot. The clock radio by the bed read 1045 and I assumed that checkout was at eleven. I consciously avoided looking at any of the pictures on the wall while I put my shoes on. I couldn't even remember taking them off. Outside I tried not to stare at the lighthouse as I put my bag and the copy of the sins of Amy Campbell into the trunk of my car and walked down the covered awning to the office once again. She was still there, still reading that feathered old paperback when I walked up, looking just as bored as she had the day before as she looked up at me with that same look of, oh, you again. Checking out? She asked. I nodded and handed her my key. She took it and asked, how was your stay? A million things that I might say flashed through my mind. I had strange dreams.  I know the feeling. She said, while she closed out the stay and wrote up my receipt, I nodded at the book laying open on the desk. Can I ask you what you're reading? She looked down like she'd forgotten the book was there. Oh, yeah, it's a book about a lighthouse keeper. She forgets to light the light and causes a shipwreck and it's about her dealing with a fallout from it and the town deciding whether it's her fault or not. It's my favorite. Is it? I asked. She slid the receipt across the desk. Yeah. Where'd you first hear about it? I asked. She thought for a moment. You know, I can't remember. I think it might have been a gift, maybe? We all have things like that. I replied. She shrugged. Well, you're all set. Thanks. I never caught your name, by the way. She frowned at me and an outside observer may well have seen just another old man trying to chat up a young lady that wanted to read. There were no outside observers, though. And she sighed as she said, Amy Campbell. I nodded. Well, thank you for your help, Mrs. Campbell. I appreciate it. I hope you have a good day. She squinted like she was surprised that that was the end of the matter. But then nodded, you too. Have a safe trip wherever you're going. I left her there in that little motel office and sat in my car a long time without ever starting it. When I pulled away, I watched the rear view until the mountains in that shimmering heat and haze of the summer day swallowed up first the motel and finally the lighthouse. I have searched for the book The Sins of Amy Campbell multiple times throughout the years whenever I'd had an odd afternoon or found myself in certain kinds of bookstores. I have never found even a mention of it, though I still have that old copy in a lock box on my own bookshelf. I have searched for that motel along that old road and though I have driven the length of that highway many, many times since and have passed the landmarks I remember from that trip. I have never found that old valley nor that lighthouse nor that old motel ever again.


Excellent. Thank you. At any point, if you find that it's getting smaller, just let me know, and I'll increase it. Welcome to the session on thinking in functional style. Actually, this title actually is wrong. I'm going to actually thinking in functional style and programming in functional style. I'm going to actually talk about, actually I pulled the wrong slides actually here, or set of content. Let me go fix it. So what I'm going to talk about here is a little bit about changing the way we think about things programming. We've been programming with object-oriented technology for quite a while, and then something else that's kind of evolving as we are looking at things. And this can give us a certain amount of benefits. I want to show you a few things. Normally, when I give this talk, I use multiple different languages. And the reason I normally use multiple different languages is mainly because mainstream languages quite could not do a lot of these things. But that's changed quite a bit. C Sharp has started doing this quite effectively over the past about a few years, maybe about three, four years, maybe five years, not as much, I guess. And then, of course, Java is just about beginning to do this. So as a result, I kind of changed my presentation just this morning so that I can give this entire presentation just in Java. If you don't mind that. Anybody minds that? All right then. So we're going to talk about quite a few things. Best time to ask a question or make a comment is you when you have it. So if you do have a question, keep it extremely short.  Go ahead, please. Java 80, that's correct. Thanks for clarifying that. This is something you can download and use it today, as long as you are willing to know that this is going to change quite drastically in the next several months as they are putting their finishing touches on it. Excellent. So yes, that's correct. Functional programming, I'm going to use Java as a tool because it's a style of programming. We could talk about purity and all that, but I'll get to the details. Let's get started. First of all, the question is why should we care about functional programming? One reason why we should care about it is everybody around us keeps talking about it. So what the heck is it? So that's a good thing to know about. Another reason to care about this is it is something that's been around for a very long time. But what's really happened very recently in time is back in about 2003 timeframe, this engineer went to his boss and said, this computer ran really fast before the chip melted. And so they realized they could not put more into this and the packaging could not continue. And they had to go back and produce multi-core processors. So because they had to create multi-core processors, as a result, multi-threading became quite viable. But the problem is this. We've been writing code for a while, but we really have not taken the ability or the time to create concurrent code that is safe. But it turns out functional programming inherently is thread safe because fundamentally it removes quite a number of problems that exist in imperative style of coding. So let's talk about what is functional programming, because we are talking about why we want to do it. It is a programming style. Again, talking about why, you can write less code, but you can write code with fewer errors. Now who doesn't want to write code with fewer errors? So you can write less code. You can write code with fewer error. It's also easier to paralyze this code. I'm really hoping I'll be able to get to that part by the end of the session, assuming that we can keep up the pace. So what are the things that functional programming really provides for us? One of the things it provides for us is assignmentless programming. Now you say, wait a second.  How could you write code with new assignments? Well, remember what structured programming is all about. We said go-to's are evil. Every time anybody even thinks of go-to, good old Dijkstra moves in his grave. You don't want to use go-to in your code. But in fact, go-to is a forbidden keyword in Java. You cannot even use it. But does that mean that there is no jumps in the code? There's no go-to in the code? The go-to happens all the time, except we don't put go-to's in the code. In a very structured, we write the code, and then the go-to happens under the covers. In a similar way in functional programming, we have assignmentless programming. Meaning we don't mutate the variables. The mutations can happen in a controlled manner under the covers. If you want to know a good word for it, we call it encapsulation. So you would say, hey, I'm looking at this library. It is doing mutation under the covers. I don't care. It's encapsulated. They take it with responsibility. We don't encap mutate it. That's kind of the point. And the second thing in functional programming is moving towards immutable state. And basically, you're not going to be modifying objects. Instead, you're going to be treating them immutable. And you're going to transform the state from one object to other. Yes, you can have concerns about performance, but there are other ways to eliminate the performance concerns. We won't go into that right now. But if we have time, we can talk about it later on. The third thing that about functional programming is that it has no side effects. And the beauty of not having side effects is that you're not going to really be mutating stuff. It becomes a pure function. It's easier to resend these functions. And as a result, it becomes a lot easier to optimize the code during execution for concurrency and parallelism and so on. But more essential in this case, the essence of functional programming also is that you create with higher order functions. So what is a higher order function? A higher order function simply says three things. Remember how you can create objects within functions? And remember how you can return objects from functions? Remember how you can pass objects to functions? In functional programming, you can do to functions what we have been doing to objects. In other words, you can create functions within functions. You can return function from functions. And you can pass functions to functions as well. In fact, the functions have raised themselves to the level to say, it's OK. I'm not going to stick to you just dealing with objects. I'll work with functions as well so they're higher order in nature. So that is basically what a functional style of programming provides for us. That's enough talking. Let's get to the code and take a look at some examples of this. How would we do this?  And I want to total these values in an imperative style, first of all. So let's say integer, and I'm going to say, for example, numbers in this case equals to, let's say, arrays a bunch of numbers as list.  And I want to go ahead and total these values. Now, how would I be able to total values in a collection? Well, we all know how to do that in an imperative style. So what is imperative style? Imperative style is where you tell it every step of the way exactly how it should do things. So you would say, for int i equals 0, i less than numbers dot size. Is it size or length? Is it less than or less than or equal to? You know what this is called? This pattern is called self-inflicted wound pattern. There is absolutely no reason to suffer through that. The programming has to be much more elegant. You don't want to go through those micro-decisions, so we won't do that. So what do we do in Java before this? We say number, and then we could say numbers. This is the 4e syntax that Java provides. And then we would say total plus equals to the number that we want to add. And of course, here we could say, for example, int total and equal to 0 to begin with, obviously. And then when we want to total this value, we could simply come down here, and then we could say what the value of the total is going to be. So we could say, for example, total, and then we could simply print the value of total. So this is imperative style, but why? This is Java code purely, but this is imperative Java code. What is it doing? You're first telling it, hey, got a collection of data. First define a total value, done. Now go through every element in the collection. All right, what do I do now? Take the value and add to this total value. So this is purely imperative. And how do you smell imperative? It's a smell. You smell imperative by looking at two things. One, you're going to be mutating a variable over and over and over. If you put your ears to it, you'll hear the variable total keeps saying ouch, ouch, ouch. Because you're constantly updating it, right? And then, of course, you're telling it what to do. Repeatedly, you're updating it and giving instructions to it. So this is an imperative style of programming. Now what would a functional style of programming do? You use a declarative way of doing things. What is declarative way of doing things? It is just to tell it what you want and let it figure out what should be done. What are we trying to do really here? We're trying to total the values, aren't we? So why don't we come down to this and say, I want to say total, obviously. That's what I'm trying to do here. But why don't we, instead of going through such a process, simply say numbers.sum and ask him to really total the values? He says, I don't find what sum is. What are you talking about? Well, we're going to go to something called a stream and ask him to do a stream on it. So what is a stream, basically? Well, a stream, basically, is a new in Java 8. This gives you a iterator. Well, we are used to iterators in Java, obviously, right? But imagine this to be not just a simple iterator which has a move next and get next and stuff like that. Imagine this to be an iterator with fancy set of functions that you can use. So this iterator can give you quite a number of flavors of methods to do. So in this case, I'm going to say, give me a stream of objects. And then once you give me a stream of objects, I want to come back to it and call some methods on it. Like, for example, sum or total the values in the collection. Let me see if that's even happier to use it. Cannot find the symbol, it says. So I'm obviously having some trouble with it. But let's scale back. We could do something else a little different. Maybe this is actually better because we can learn something from how this is going to really work. So I'm actually getting a stream. And I'm going to say, what am I trying to really do? I'm really taking each of these values. And I want to go through a totaling of these values and do a collection. In other words, we are trying to perform a reduced operation. That's what we are doing, right? So let's imagine how this would work. Now, we said we're going to total everybody the values, but without mutation. You're going to sit there and say, how in the world can you find a total without really doing mutability? How in the world can you do that? Well, let's take an experiment for that. Imagine for a minute, I want to total the age of everybody in this room. Let's think about that for a minute, right? And I'm going to start with you. He's not smiling anymore. No, I'm not going to ask for your real age, right? So I'm not going to ask for your real age. But there's a rule. I'm going to pass around a post-it note. But there's a rule about this post-it note. This post-it note is a write once post-it note. You can write on it once. But once you write on it, you cannot erase it. You cannot rewrite on it. You cannot overwrite on it. So on this post-it note, I put a zero, first of all. And I gave it to him. And what is he going to do? He's going to take his age and total to the value zero, right? But he cannot change this post-it note. What can he do? Take another post-it note. Absolutely. He takes another post-it note. What does he do? He gives it to him. What's your name, sir? Taj. And what does he do? He totals his age to the number that was given. And what does he do? He passes it down to her, correct? What does she do? She takes her age, subtracts 10 from it, right? And then totals that number and passes it down, right? Makes sense, correct? And if we continue with this way in the back over there, the last person giving us the post-it note would give us the age of everybody in the room, agreed? But how many post-it notes did we torture? Did we mutate? Not a single one. Because we keep creating new post-it notes.  But imagine this. One of the things we have really nicely in Java and C Sharp and all these languages is what?  You know, call me silly, but other day I was programming. And it suddenly dawned on me. How would it feel like doing this in C++, where you have to keep calling delete? That would suck, isn't it? So we can leverage that. So absolutely we can get this total at the end. So what am I going to do? I'm going to say reduce. And to the reduce, what am I going to do? I'm going to start with the value 0. What is the value 0? We just agreed that I'm going to give him the value 0, right? And then what are we going to do? We're going to pass a function over here to this. And what does this function do? The function says, I'm going to take an element value, which is the age value, if you will. And I'm going to have a carry over value that you give me. And I'm going to return from here an element plus the carry over value. So just take a look at this code for a second. What are we telling this particular code? We are telling this code. I'm going to give you a reduce method. And I'm going to say, take this element value, take this carry over, and return the element plus carry over. In other words, all that I explained in English to you is a reduced operation. I'm reducing everybody's age in this room to a total value, which would either be a value or overflow, looking at all the people with gray hair on the room. Just kidding. I've got quite enough of that myself. So basically, the idea really is we're performing a reduced operation. Now, what did we do, though, in this particular context? We did not sit there and tell him every step of what to do.  And what did we send to this function? We sent an object, 0, as the first parameter. But the second parameter we sent to the reduce method is not an object, but we sent a function itself. So what is a function? Most of us would say a function has four things. A function has a name, a function has a parameter list, a function has a return type, and a function has a body. So a name, a return type, a parameter list, and a body. Of the four things, which is the most important thing. Thank you, body of the function, right? Absolutely. Hey, where's the body of this function? In what I've highlighted, the body of the function is the right of the arrow. All right, one down, three more to go. Where's the parameter list? That's to the left of the arrow. Hey, wait a second. But parameter list normally has the types of the parameters and the symbolic names we give for the parameters. Yes, that's true. So if we really, really, really, really wanted to, we could go back here and say integer or integer, depending on what you want to do, and you could do integer. But the Java compiler says, eh, you don't have to give it. And when the Java compiler doesn't want it and you still give it, that is called what? Ceremony, right? So you don't have to go through the ceremony. It's just perfectly fine. And it infers the type automatically. So two down, two more to go. Hey, what about the return type? The return type is inferred by the Java compiler as well. And if you return something that's not correct, it'll give you an error. And of course, finally, the name of the function, hey, who cares when everything is done what the name is, right? It's working. So this is an anonymous function that we are creating. Well, we are creating and passing this function down to the reduce method. Sounds good so far? Now, this is an imperative style to functional style. But we will take a look at more examples of this along the way and how this works. So I not only showed you the imperative style, but also the functional style of doing this. I want to iterate over the collection of values. How do we do that? We already kind of did that. But let's kind of look at this one more time. What we're going to do here, let's kind of go through the exercise of doing this. We could say far int i equal to 0, i less than, we could say, numbers dot size and then i plus plus. And then we could simply output the value. For example, in this case, we would say, numbers dot, actually this is an illicit, right? Get i. And notice the effort we have to put to go through this. And in fact, I can't even write this properly, right? That's a lot of effort to write this. So this is a traditional effort. It's very noisy, as you can see, right? And I apparently put, you know, I've got to check if I put the right parentheses or not. Why go through it? That's the older Java version. We could instead go through this one more time and say far, and we could say int number. And then it is less noise, as you can see. And then we could say numbers. And then we could simply say output and simply print the number itself. This is a lot more civilized way of doing things. I think I'm missing a little parentheses down here. There we go, the curly bracket. There we go. So that is basically much more civilized. But we don't even have to do that in the recent version, or the next version, which is more, you know, a functional or declarative, rather. We could simply say numbers dot. And then we could say for each. So what are we doing in this particular case? We are telling him, rather than me telling you how to really go iterate through, I don't have time for that, right? That's what you're saying as a programmer. My job is to get things done, not to sit there and tell this every step of the way. So you say, hey, here is what I want you to do for each element. You go figure out how to loop through it. Now you say, what's the benefit? Well, there are two benefits of this approach. The first benefit is you don't have to tell in the silly stuff. But the second benefit of that is because you're not telling him the silly stuff, the code under the covers can decide how to do it. It could do it sequentially in some cases, or it could do it concurrently or parallely in other cases. So by encapsulating that below, we get a lot better power on our hand, right? So by not doing things, you not only eliminate the effort of doing it, but you give the opportunity for somebody to vary the way they do it too. So less control actually gets more functionality for us, isn't it? So what am I going to do here? I'm going to say, in this case, integer over here, because I want to take an int value. And I'll say number. And what do I want to do with this number? I'm going to simply output this and say number and ask him to print it. So this is basically a number we are receiving. And I'm asking him to go through the number. And I'm asking him to print this value out for us. That's what we are doing. So there you go, it printed it. But of course, this appears a bit noisy as well. But it's far less work than what we saw before. But we could say, you know what? I really don't want to specify the type. That is kind of inferred. So you're reducing the noise quite a bit, as you can see. But Java 8 actually gives you a little bit more capability than this. If you look at this code, what are you really doing? You're saying, receive a number on my left hand and pass it down to this function on the right hand.  Because that's so obvious what we are doing. We're receiving a parameter and we are sending it. So Java 8 says, if that's what you do, don't write that much code. So we can simply remove this number from here. And we can simply replace this with a double colon. And this basically is called a method reference. And then you can get to that point as well. So this is basically going towards a more declarative style, removing the noise. There's a very good saying that says perfection is achieved not when there is something else to add, but when there is nothing more to remove. You bring it down, strip it down to the very bare minimal. And all that you have is essential code in front of you that does the work, and all this clutter and ceremonies that distract us. So that is an example of a declarative style of coding where we are using a lambda expression plus a combination moving on to a method reference that we are using. So it gives us clarity, it gives us focus. But like I said, don't discard the other benefit, which is we don't have a clue how far each is implemented. And as a result, it can be implemented in one of several ways, depending on what we are trying to do. Excellent. So we looked at some of these combinations of things. We looked at what Java 5 can do. And we also looked at what Java 8 can do. I want to double the values in a collection. And again, how would you do this in a more of an imperative style? Well, if you want to go loop through these again, you would want to double these values. Or how would you go about doubling these values and then print it? Once again, you know how you would do this in the traditional style. You would say, create me an integer, and you would call it doubled equals new array list of integers. Well, thankfully in Java 7, you don't have to put the type over here because you can reduce that noise. So that is Java 7 syntax already. Then you could say int number in numbers, basically. And then in this case, you can simply say, now that I've given the numbers, you can say double dot add, and you can say number times two. And then of course, when we are done with this, we could say, print me the doubled value for me in this particular case. Well, again, we could go through all these steps. Now, what do you think of writing code like this? How do you feel after writing code like this? Not very good. This is very low level right. And if you're working from home, this is dangerous.  Because otherwise, the kid looks at this and says, that's what you do for a living. And then no longer they won't take up our profession. So we've got to be very careful what we show to the kids. So obviously, they say, you are writing intelligent code, not kind of silly code at a low level. There's another name for this. It's called primitive obsession. We are sitting there at a very low level writing code. We don't have to do that. So instead, what we could do is we could simply say, I want to take these numbers that you give me on my hand. And I'm going to say, give me these numbers. And what do I want to do? I'm going to go to the stream, which is the fancy iterator I talked about. And then I say, do a map. Now, what is a map function? Notice what we are doing. We are transforming from a collection of numbers to a collection of double the numbers. Where is mutability in this case? That's not our concern. You have an input collection coming in, and you've got an output collection going out. That's all you care about, right? So this is purely a transformation.  And that is all you care about. So you pretty much focus on the logic you want to implement, rather than the mechanics of how do you loop through? Where do you multiply? Where do you stick it back in? All the details of implementation can be totally removed from your site. So the idea, really, is to say map. And what is the mapping I want to do? Given a number, I want to map it to a number times 2. That is the mapping that I want to perform. That is the lambda expression we are sending. So map is a function. But what we are sending to the map function itself is the value of the function that performs the multiplication operation in a sense. So rather than, again, focusing on the mechanics of looping and doing the work, you're just telling them what you want to achieve. And you are only providing what you can provide. Who here knows what you're trying to do? You, right? You know that you want to multiply or subtract or you want to square it, but everything else can be taken care by the system under the covers. Now that I have a collection of these values, I want to print it. So in this particular case, I'm going to simply say, given a number, I want to transform it. So this number is the doubled number. And I'm going to simply say, take an integer dot 2 string value and then convert it to a number, right? We're saying convert it. And at the end of this, I'm going to collect it back to what? To a list. So I'm going to say to a list. So you started out with a collection. And then you are coming back into a collection. So I'll explain what this means in just a second. Of course, for me to use this, I need a few more things to import. So I'm going to import Java dot util dot stream dot star. And I'm actually going to bring a bunch of static methods in here as well from a collector. So I'm going to say static. And I'm going to say collectors. And let's go ahead and use that. So what am I doing in this particular case?  Let's make sure this is working before we continue any further. The output is the same, but what did we just do? We simply said, given us numbers, get me a stream. Remember what stream is? It's a very fancy iterator that you got. And then on the iterator you said, transform the collection of numbers to the double of those numbers. That's what you said. Then you said, well, I have these numbers. I can then further transform that to a collection of strings if I wanted to. But the point really is you could go on and do more work. You can do any number of work. This is like saying, I can give you something. You can do part of the work and then pass it on to him to do more work. And then you can continue until you say, we are done. And you can get the result and bring it back. And then finally I say, I've gone through the sequence. I no longer need the sequence anymore. I don't need this iterator, but I want a collection back on my hand. So you're collecting the end results into a list one more time, and you could then go on process other things in the list if you want to. So this is all intermediate operations you're performing along the way to get the results that you are interested in. So we looked at more of a functional style of doing this as well. So we are slowly marching on into another interesting thing we can do, which is function composition. A function composition is a very powerful way of doing things. The beauty of function composition is, how does the business workflow look like in problems we solve? Normally the problem statement says, take this particular information, do this operation with it. Get the customer's invoice, process all the entries, validate each of the invoice entries, send it to this particular system for verification of the particular end and on and on and on. So we take all these requirements. And then what do we do? Then we unleash the programmers on it. And then they go write the code, and then say we are done, and you open the code, and there's like 1,000 lines of code sitting in there. And you say, what do you think? Does it work? Is this what you wanted? And nobody can read it anymore. Not even the programmers who wrote it can't read it anymore. This is one of the things that fascinates me. When Java came out, we were saying, how do you upfuscate this? I always ask, why do you want upfuscation tools? Java programmers do a good job already, right? Nobody can understand the code. So it really becomes hard to understand this code. It's all cluttered up, right? Well, what if the code kind of reads like the problem statement? And you're looking at the code and saying, yep, yep, yep, yep, that's exactly what I wanted to do. Now you can have people look at this and say, eh, not quite. Or they come back to you and say, no, we want to insert something right in the middle. Not a problem. You insert it right there in the middle. And it gives you, this by the way in good design, this is called the difference between opacity and transparency. Opacity is where you look at the code and your head hurts, right? And you cannot see through it. Transparency is where it's very clear, it's obvious. So you're able to look at it and say, yep, I get it, this is what the code is doing. So that is basically where you can lead with function composition. How would we benefit from this? Let's take a look at an example of how we would do this. So here's the problem I'm gonna take. Find the total of even numbers in a list. Actually let's make it even better. This is one of the advantages of changing the top on the line, right? So find the total of, find the total of double of even numbers in a list. How about that? That's even a little bit more in terms of flow. So I wanna find a total, all right? But what? Of double of some numbers. But what numbers? Only even numbers in a certain number collection. So how would we do this in imperative style? Well, we know how to do that in imperative style already, right? You would loop through it and maybe in one shot you would check if it is an even number. And then you would say, well, actually it's kinda right at least a pseudo code for it if you wanna kinda look at how that would look like. So what would you do? You would, first of all, you would write one loop, like we already have a loop here, we could do this, right? So what would you do in this code? You would simply say, for each number, so you would first define a total, right? So it's a int total equals zero to begin with.  Then you would say, if number is even, so you could say number pound two equal to zero. Well, if it is, what would you do? Then you would say total plus equals number times two. Well, that's what you would do, right? And then when you're done with it, you would actually print it out. So that's a total value, assuming I did it right, it says 24. And you look at this code and say, hey, that is simple. Well, okay, that is very arguable if this is simple. Why is this arguable? And the reason is, oftentimes we confuse the word simple to some other word we really mean to use. That word is called familiar, right? This is not a simple code, this is a familiar code. But what is familiarity? Familiarity is what you are used to, right? I may be familiar with something, and you may share that. We both are familiar with it. But on the other hand, he may say, I'm not familiar with that, I'm familiar with something else. So now is it simple? Well, that's still subjective and questionable, right? So this is the code that's familiar. But why is it familiar? It is familiar because we all have done this for a long time. So don't confuse the word simplicity with familiarity. In fact, I would argue this code is really not simple. It is actually hiding behind certain things. Now look at this for a second. What are we doing? We first of all took a total value, and then we loop through it. Then we check if the number is even, then we double the value, then we total it. Now what is the, so when you describe this, how many times do you use the word end and then? And if you do all of that, what are you doing? You are violating the so-called principle called the single responsibility principle. This piece of code has multiple responsibilities. It's got the responsibility to total, it's got the responsibility to double, it's got the responsibility to find if it's even all that clubbed in. Now you come back to this code and you look at this, will you be able to understand this code, right? Now, what about understandability of code? The worst person to read a code is the person who writes it, would you agree? Because you write it, you know everything, you look at it, and you always understand it. But how do you normally feel when you look at somebody else's code in your company? You come and sit in the desk, you open this code, and you didn't write this code, you look at this, and you have a thousand self-complaints about it, right? You start saying, I don't like this, I don't like this, I don't like this. In fact, this even happens when you keep saying this until you realize this is actually the code you wrote and don't remember. Now it doesn't look that bad anymore, right? So you kind of get that feeling. But what if this is actually clear, you can read it, you can understand it. So let's see how we could do this in a more of a declarative style, in a functional style. So notice what I'm gonna do. I'm gonna go back to this code and say, I wanna output. Well, what do you wanna output? I wanna output a total of values, that's what I wanna output. From what? I wanna take numbers first of all, and I wanna get all the even numbers first, right? So stream, and from the stream, what do I wanna get? I wanna put a filter operation on him. So what is a filter? You're saying, I've got, so think about this for a minute. I've got a bunch of coins with me, and you come to me and say, hey Venkat, you got all these coins, but I wanna separate these coins. I only want 50 prices out of it, right? How would you do this? Man, you could sit there and mechanically look at each. That's one of the best ways to get old and die, right? Instead you say, here's a filter, throw your coins in there, we'll just kinda shake it up, and the right coins fall out. Well, that's your filter method, right? So the filter method basically says, send this collection through this fancy elevator we looked at, and only filter out the values that we really care about. Well, what are we really caring about? So given a number, tell me if a number mod two is equal to zero. You see this little function, right? Little function let or functionoid, whatever you wanna call it, we call it lambda expression, that we are passing to this function, is gonna return a billion, a or nay. If it says yes, that value is included in the future, if not it gets dropped out, right? So think about this as a pipeline, values go through this pipeline, if the value is true, it continues on the pipeline, if not it gets dropped out, right? So it continues further, what do I wanna do now? All right, now I filtered it, and if you really, really care about writing readable code, you could do this a little differently. Why don't we do that? We do care about readable code, right? So why don't we say this? Let's say public static Boolean, and what is the Boolean here? Is even, right? And is even what? I'm gonna say is even of a number. So let's go ahead and say int number, and in this case I'm gonna simply say return, and number mod two is equal to zero. So now I can simply come over here and say, sample colon colon is even. Notice how readable this code kind of becomes. You are saying take this collection and filter is even, right? You know I hear people tell me, oh functional code is unreadable. What they're telling you really is they are unfamiliar with it, right? Now of course you can write bad code in anything. If I really am adamant about writing bad code in functional programming, nobody can stop me, right? Well hopefully colleagues of mine will stop me. But the point really is, we could actually write readable code, and you can say filter through and only get me, did I put it in the wrong place? Yeah keep an eye on me, don't say yeah later on. These guys are watching me do wrong things. There, yeah, absolutely, right? So now what do I do? Now that I've filtered out even values, I need to double these values. You could write them into a separate function if you want to. In this case I'm gonna apply a map function, and I'm gonna say given a number, get me the double of that number. Or we could write a static function or an instance function that says double it, and then you can just call it. Now that we are done with it, what do I wanna do? I wanna total the values because I'm really trying to find the sum of all the values together, isn't it? So notice how that worked. Did somebody raise their hand with a question? Yeah please. That's a great question, awesome. I'm so glad you asked that question. Brilliant question. He said, when you looked at the first version, you iterated only once through the list. So what you're implying to me is, hey come on over here, what about performance? Are you iterating through this several times? A brilliant question. So why don't we do something else to answer that question? I'm so thrilled you asked that question. So let's go back here. So let's go back to this guy here, and let's say sample dot double it, double it. So let's go ahead and create a double it. So public static, and this is gonna be integer, and we'll call it double it, and that takes a number, and we're gonna simply go ahead and return a number times, oops, number times two. So let's make sure it's still working. All right, seems to be working fine, right? But let's do something you should really not do, but just for your purpose, I'll do this. And I'll simply say here, is even called on number. I'm just gonna print it. Now by doing this, this function is no longer pure, right? So keep that in mind, don't do this too often. And then over here, I'm gonna say double it is called over here, right? So let's take a look at this and see what happens. If you kind of look at this with your naked eyes, your observation is absolutely correct. But you see, I have glasses, right? So I'm looking through my glasses, and I'm not seeing what you're seeing. What I'm seeing is this stream, the stream I said is a fancy iterator, but it's got another capability, and I have only seen my children have that capability as well. They are lazy to the bone, right?  And they actually have not done anything. They're still sitting there playing video games, right? And then you say, let me see your work. They quietly sneak to the room and get the work done now. That is exactly what the stream does as well. It is a lazy collection. So when you said stream filter, he's like, yeah, I'm done. He didn't do a job. Then you call map on him, he says, yeah, I'm done. He didn't do a job. Then you call some on him. He's like, oh my goodness, let me go do this now. So this entirely clubs it back to one collection quietly under the covers. So it did not do multiple iterations, even though to our naked eyes, it appears it does, but this is a lazy evaluation, extremely smart implementation under the covers. Remember, you're passing a stream object to filter. It doesn't do the job. Instead, it returns another fancy collection, which didn't do the job, but caches the operation and says, I will do this later on when I really, really have to do this, right? And then you then call map. It doesn't do the work. Instead, it passes another fancy collection which caches that operation. Then you call some. He says, oh, I got three operations lined up. That's one looping and does it. So if you notice the output in this case, what's gonna happen is, it is not gonna evaluate all of that. I'll come back to this in a second to show you a better example in a minute. So I run this. Notice it says isEven called so many times. It called isEven on every single value, correct? Right, agreed, right? But rather than putting the sum, I wanna find first. Now, what does find first do? It says, find me the first double of an even number. Now, if I naively do this, what will happen? I'll go through every element and check if it is even agreed. Then I will start an iteration one more time and I will double each of the values. And I'll give you this collection. Then I would say, ah, I'll cherry pick the first one. And you look at me and say, this is dumb. You wasted all this effort. Let's see what happens now. I'm gonna say, get me the first element over here. And let's see, when we run this, let's see what happens. In this case, I'm gonna go, ah, let's see what he's complaining about. They get operation on optional int. It is gonna be getInt. So let's go ahead and try this out. And eh, cannot find getInt operation also. You know what, let's not worry about that for a second. Let's just print the optional for a second. Why worry about that? That's not the problem we're trying to solve. Notice what happened. He said, is one even? Yes, it is. No, it is not. What about two? Yes, it is. And he didn't go to three. He didn't go to four. How come he knew that? Because this has been clubbed together under the covers, right? He said, yeah, I found the first even. And he says, hey, map, take care of it. Map says, double it. And gives it a fine first. And fine first says, I'm done. Hey, what about all the other work? I go home, right? So notice how this optimization happened. So this is one of the beauties, is that it knows to optimize under the covers. So you've got the performance while you have the clarity. A awesome question. So that is exactly what's happening in this particular case. Excellent, please. Sorry, say that again. Let's not worry about it. I will avoid syntax related questions here. You see what I'm saying? And we can take it offline. Let's keep the focus on the paradigm. Awesome. So, all right, that's great. Let's talk about kind of clubbing this all together. Yes, please. A little louder. I'm not good at hearing. Execution time. Tell you what, let me build up another example which will kind of bring the clarity of execution time. How about that, right? So let's do that. And if you really want to look at this again, we'll take it offline. But I do have an example with performance. I'm really trying to rush through that to get to that point. But good questions keep them coming though. Excellent. So what do I want to do? I want to go to do a certain operation and we'll see how difficult or easy it is to do this. So let's give it an example.  So let's get rid of all of this for a second. And I'm going to go to just the main method.  So we'll call it tickers.  It's called tickers.symbol. So I'm going to say list of string. Keep an eye on it. I'll make mistakes while I type. I'll call it tickers equals tickers.symbol. So symbols. So I've got tickers and I've got the ticker symbols. All that I'm doing is referring to it. That's all I'm doing. So let's start with this. I print all the ticker values. It just prints the collection for us. I've got a bunch of stock prices. Now what do I want to do? My problem statement is this. Find me the highest priced stock, which is less than $500. I always have to quantify that. Otherwise, I always get Google or Apple as a result. So I'm going to say give me a stock price, which is $500 or less, but give me the highest price. Make sense? So what are the steps involved in doing this? Think about it. I've got the symbols. What's the first thing I need to do? Get the prices. I've got a collection of prices. What's the next thing I have to do? Filter out the ones which are $500. What's the last thing I have to do? Find the maximum. Got it. Let's see how we do this in an imperative style. We would first of all say, in this case, I would say a list of stock prices. Now what is a stock price? I have a stock price. You would actually call it stock info. You would, in a familiar term, call this as a Java bean. So all that it does is it contains a stock info. You can create it. That's all it contains. So nothing really spectacular. Just a data object. So stock info. And this is going to be a stock prices. Let's call it. So equals to what? New array list of stock info. That's all we got here. So I created an array list of stock info. Now that I have this data object, what do I want to do? The key here is that I want to really fill up this collection. So we would start with string ticker. And then we could say in tickers. This is the ticker symbols we have. And then I want to go find the stock price for each and every value. How do you do that? Well, you've got to have a service to provide you the stock prices. Well, it turns out there are a couple of services out there, but we could use Yahoo service. And I'm going to go to Yahoo and say, hey, Yahoo, can you give me the stock price for me, please? So I have a stock util over here. The stock util is a convenience class. What does a stock util do? It says, go ahead and get me the price for me from Yahoo Finance. If you're curious about how I get the price from Yahoo Finance, it is just a code that parses the response from the web service. It is not a good idea. It is not manners anymore to show parsing code in public. So go to your privacy of your home or office. Keep it away from the children and take a look at the parsing code. That's fine. But that's the code we're going to look at. So what does get price do? It just gives me a stock info. So I'm going to simply call stockutil.getPrice. And this is going to give me a ticker. And it's going to give me the price for it. Now, what do we do with this value? I'm going to stick that into the stock prices over here. So stock prices, I'll call it stock prices in a second, dot add, and I'm going to add this to the ticker prices. So we'll call it stock prices. I'm making sense so far. Okay, we got this value here. Now, what is the next thing I want to do? You said the next thing I have to do is go ahead and pick the values which are less than 500, right? That's what you said. Now, what would I do to do that? I would say here a list of stock info one more time. And we would say stocks less than 500 equals muArrayList one more time. And in this case, I have to repeat the loop. But this time it's going to be stock info, we'll call it stock, in what? In stock prices. And this time around, I'm going to say if, well, I already have a function for it. So stock util one more time. And in the stock util, I'm saying is price less than, right? So I'm just going to call it. So I'm going to say if stock util is price less than $500, so this is going to be stock, 500, then what do I want to do? If it is really, I'm going to simply say at this point, go ahead and go ahead and add it. So stocks less than 500 dot add. And this is going to be the stock. Am I making sense? You say, wait a second, but why are you doing it in two loops rather than one loop? Does anybody have an answer for it? Single responsibility principle. We talked about it, right?  What's this doing? It does this, and that, and the word and, and then reveals that you're not doing single things. Why are you not writing code like this normally? Performance.  So we are compromising readability of code for performance. Make sense? But in this case, of course, I compromise performance for readability. And you're going to say you would never be in the enterprise if you do this, right? Yeah, that's kind of the reason to do this in a better way. All right, we got that through. What's the next thing I want to do? Now that we got through that, we got to pick the highest price from this. So I'm going to say stock info. We'll call it as high priced equals. And this is going to be a new stock info. And this is going to be just an empty value with the price 0, 0. Start with a lower value, lower bound. And then I'm going to loop through this one more time. In this case, stock info. We'll call it stock. But this is from stocks less than 500. And this time, I'm going to say high priced equals. And once again, go to the stock URL. I've got a method called pick high, which will pick the highest priced value from both of them. So I will simply say, over here, stock util.pickhigh from what? Pick high from the high priced and the stock itself.  But before we go run this, normally you would never see me write what I just did. Every step of the way, I'll be running this code. But I also know that the internet connection is extremely poor. I'm actually following what is called the anti-pattern that actually Neil talked about in his presentation. And the internet connection is pretty darn slow. That's why I kind of wrote the code in length before I ran it. So basically, what I'm going to do here is simply say long start equals. And I'm going to say system dot nano time. And I'm going to measure the time for the beginning. And let's just do this right here, right after this. And then I'm going to come down here and say long end equals system dot nano time one more time. And now we will say output end minus start divided by 1.0 e9. So basically, we're asking him for the time that it takes to do this entire thing. I'm running this code. It's not given a compilation error at this point, which is scary. But this usually takes anywhere from 20 seconds to three days to run. So we got some time to kill. So questions so far. Keep the question very short. 10 seconds. I'm giving you 10 seconds. Keep it short. So there's normal programmers and polyglot programmers. I want normal programmers to become polyglot. How about that? Again, the familiar, the normal, is a new norm. That's it. Any other questions? All right. So we went through this. And like I said, the reason we break this into multiple loops is to give the clarity. You would not do this in a regular imperative style because of performance concerns, right? How much time did it take? 61 seconds. And Apple still came through. Sorry. So far so good. Can somebody note this down so we can make sure the parallel version we write is the same? I'm sorry. The functional version we write is the same. So 61 seconds. Give or take. And then $430.47. Did anybody write it down? Thank you. Now let's go and write this again. So let's go back to this code and try this one more time. How many lines of code did I write? Anybody notice? About 20 lines of code? Something like that? All right. So let's close all of that. Let's try this a little differently. I'm going to say public static. So what am I going to do in this method? I'm going to say find price. So we'll just say find price. And this is going to take a stream of strings, right? So take a stream of strings. We'll say tickers. So what am I going to do in this code? I'm going to say, all right, you gave me a ticker, right? So tickers, what's the first operation I should do? Help me out. Tell me in words I understand in functional style. Three-letter word. Map. That's correct. So we're going to do a map. And map of what? Given a ticker, you want to do what? Get price, right? Stock, you tell. Get price. Are you with me? All right. What's the second thing you want me to do? Filter. Stock, you tell. And what's a filter operation? I want to start with this new stock info, empty and zero, right? And I want to give him a function. What function do you think I should give him? Big chi, right? Are you with me? And when we got all of this value, my last step is to print it out. So let's go back here and print it out with me. We want to know how much time this takes. So this is going to be start equals system.nano time. And of course, at the end, I want to know what the time is. We'll include the time of printing also here, no big deal. And we'll say system.nano time and output. Thank you for fixing. I love pair programming. Start divided by one point. I'll finish this and go fix E9. And this is going to be system. Does it look OK so far? Are you happy? So this is purely a declarative style, right? So look at the reading of this. We came in and we said, go find the ticker. Go get the map of all the tickers to stock prices. Filter out only the prices less than 500. Reduce it down to the high price. So far so good. You can easily inject new things in the middle if you want it to, correct? So let's see what this guy did. So let's get back over here. I don't need any of this stuff anymore. We'll comment this out also. So let me make sure I have the main empty right now, except for the tickers, correct? So let's go ahead and call find price tickers.stream. Happy? Assuming I wrote all of this correct. It should give us hopefully the same price. The market is closed right now. And it should hopefully take about the same time give or take. That's kind of unpredictable depending on internet speed. But we can put in a buffer of values to make sure that happens. So which of those two would you want to write? The first one, of course, if you're a consultant getting paid by the number of lines of code you write, right? But on the other hand, if you want to get your work done and go home, the first one is better. If you want other people to understand what you're doing, the first one is better, right? Now notice the transition from one to the other. If you only focused on that one loop, that's hard to go this route. But we said, separation of concern, do these steps. Ignoring the performance for a minute, then you're saying, ah, I can plug each of those into a separate step and do this particular operation. So that becomes a lot easier to work with when we do it that particular way. So that is an example. You say, all right, what benefit did we get so far? Well, the benefit we got so far is we are able to write readable code. We're able to write less code. You say, okay, okay, well, all right, all right. It's less code, all right, but I like programming. Shouldn't I be writing a lot of code? Well, if you really like programming, you want to write a lot of production code, not a lot of code that doesn't do anything, right? So that is great. The second benefit you get out of this is that the code is easier to understand, right? It's easier to understand. And again, like I said, don't look at that 83 seconds. That doesn't make sense because the network is the delay here, right? And if you're really interested, we could put a little dummy value and try it out and you will see it. But you say, all right, but is that all the benefit? In fact, the performance will be exactly the same because we didn't do anything different in this case. So, but here is the beauty. You say, all right, this is all great, but before we go further, let me ask you one question. Look at this for a minute. What are you doing here? Going to Yahoo and getting the price, agreed? What are you doing on the next line? If I can see the line number from here, that line with the one on it, filter.  That's a math operation. What are you doing in Reduz? You're comparing prices. Which of these is the slow operation? Going to Yahoo, I would assume. Right, yeah? You're going all the way to Yahoo. If you say the math is really slow, you need a better processor, right? You're going to Yahoo is the slowest part. Doing the math is the fastest one. Which of the one is the most compensious? The Reduz, isn't it? You gotta compare and select one.  Waiting for Yahoo to respond. Why don't you do something else? What, like get a cup of coffee? Why don't you send multiple requests to Yahoo at the same time? What's the benefit? Well, Yahoo is going to take some time, right? Two seconds, whatever that is, depending on the network delay. Why wait till that comes back to send the next request? Why don't you just take all of them and, pluf, send it to Yahoo? Yahoo will say, whoa, last time we came with one request at a time, now you got 20 requests at the same time. Guess what, that's Yahoo's problem, not yours. So why not do that, right? Now, imagine you're at work and somebody comes with this brilliant idea. What do you do? You look at them and say, what are you smoking? Do you know how hard it is to paralyze code? And especially if they tell you this when performance is critical, which doesn't always happen early enough unless you follow it because advice to keep that in your eyes all the time. What happens? You're like, no, we can't change this right now. It's too hard and it explodes on your face. Bugs creep in, right? Or you go back and say, really, is that what you wanna do? Yeah, okay. So how about, did I spell it right? Parallel stream. What did I do? I just changed that one word from stream to parallel stream. Why? Because my functions are pure, remember? They don't mess with data. They're not changing stuff behind us, right? So we didn't do any of that. So we are running this. Again, we are incurring the network delay here, but typically this would take a lot less time than going through. And what I will do is I'll change the time delay and mark up a value for you. That way we won't be dealing with the network. Network is completely unpredictable here, as you know, right? You've been trying that. So when this fails or when this finishes, I will go mark out the value and then we'll see how much time it takes. And then we can kind of measure the two and see, okay. That's 40, that's not really realistic. Let me go fix this. So I told you I won't show you the Yahoo finance, so close your eyes so you don't see this. So basically I want to mark up this value. So let's go ahead and kind of get rid of all of this for a second. And I'm gonna simply mark up a value, right? So I'm gonna say try thread.sleep one second, right? One second and then catch exception. So we kind of gave them a delay and then return 12.12. So all of them are the same price. You already saw the code is working. So it doesn't matter what the value here shows anymore, right? So let's go back to this guy. Do the stream thing first of all, run it. And actually now that I've marked this up, we should be able to run all of them at the same time, right? I've given a second delay, so that's a 20 second. I don't remember how many stock prices I had, but doesn't matter, right? So that is the sequential execution. If you're interested, you could try the other commentator code and run this, but trust me on that, they take exactly the same time, right? No difference. How much time does it take? 20 seconds, correct? Obviously. Let's go back to this and say parallel stream and let's see what it does. So this guy is gonna go send out all those requests concurrently and there is the 3.0 second, right? How does that sound? Sounds reasonable? That's all I have. Thank you.


Hey, I'm Andrew Connell. This video is an overview of one of the chapters in my course, Mastering the SharePoint Framework that's available for purchase on my site, boytanos.io. This overview video is going to give you an idea of everything that the chapter covers. You can learn more by checking out the description and the notes below the video. If you've got any questions about this chapter or about the course in general, just make sure you drop a comment below the video and I'll be sure to get back to you. So with that, let me get out of the way. Enjoy the overview to this chapter. Once a SharePoint Framework solution has been deployed into production, there will likely come a time when you need to upgrade and add new features or address issues with the existing version. But versioning is not just about the code that you write. You should also be familiar with upgrading and managing your development environment. Specifically, in the case of the SharePoint Framework, you need to understand how to manage and upgrade the versions of SPFX and the related NPM packages. In this chapter, you will learn how to properly upgrade and version your custom solutions as well as manage the related NPM packages. I'm going to start with an overview of semantic versioning. It's a schema for a certain kind of versioning style that you can adopt and that SharePoint adopts for the SharePoint Framework, as many other projects do as well. We'll also look at how versioning comes into play with NPM and how SharePoint, the product or the server, actually takes into account different version numbers. Then we're going to look at NPM package versions and how we can manage and manipulate those. And then we'll look at versioning the project or the code associated with the things that we're building related to the SharePoint Framework. Before we begin, I want to address a unique characteristic about this chapter. When it comes to updating code in your project, some aspects are global to all projects like version numbers and versioning packages. However, some upgrade tasks are unique based on what your project is doing, such as the case when provisioning SharePoint assets. Instead of making this chapter a central place for all upgrade tasks, covering each upgrade task, this chapter will focus on the most wide-ranging aspects of upgrades. Chapters that cover topics with specific upgrade attention will have upgrade details within those chapters. Refer to the notes under the lessons in this chapter for references to relevant chapters and lessons when it comes to upgrade tasks. In addition, I'll update this first overview lessons notes in this chapter to contain a roll-up of all these different references. Okay, now let's get on with the chapter.


David, I have Rony here yesterday.  There's no Thing a man can do to manufacture it It's just God's healing power. That's it Some of you in ministry looking on and wondering how how do the miracles happen? How do we see that pastors leaders if you're wanting to see miracles? Just challenge the people to believe It's a trust fall backwards into God's hands You say God you said in your word you would do it and because you said in your word, you'll do it I step out in faith believing you're going to do it and he does it Leave the rest to God It's time to see miracles in the church again Okay, help our friend back to his seat God bless you always a pleasure What happened Ruben? I have Josh here. That's actually Rony's son He dislocated his right shoulder six to seven years ago during about scabami baseball I'm sorry, and he said ever since six seven years ago He's had sharp pain on his right shoulder, and he said as he was worshiping He was able to notice that he was able to lift his arm high and he said he said he received this healing So you didn't even notice you were healed until you went to worship It was a weird feeling because my arm was lower than my left arm and then it just popped right up So I was like this full of time and then my arm just went like this and then I could just go like this It was amazing And it was for six years you dealt with that pain What did you feel when God touched you it just instantly the pain left or was there something else?  I Don't I don't know how to explain it because it's his power. It's his power Thank You Lord for this healing And Lord use him for your glory in Jesus name In Jesus name Thank you for watching Encounter TV. Don't forget to subscribe and click the notification bell Also, help us spread the gospel of Jesus Christ in the power of the Holy Spirit Make a one-time donation or become a monthly supporter by clicking on the donate link now


Will Godara's dad used to tell him all the time, adversity is a terrible thing to waste. I love that statement, right? Like you're running a new restaurant and you just feel like you're hitting wall after wall after wall and that you're not making any progress. You know, two steps forward, three steps back. Bologna, those three steps back are valuable. Like that adversity is valuable. It is honing and refining what it is about you that you like and the things that you want to shed. It's teaching you incredible lessons. So that adversity, I mean, the amount of negative press Kansas has got are bad reviews, man, those things shaped us. They woke us up and we all need that. I don't care who you are, but we need that. We need someone to say, you know, hold on a second.


I want to say a few words about my experience of recording these courses at the Virtual University. It has been a fantastic experience. It has been an eye-opening experience. I have never done anything like this. It was very taxing on my part. It took me a lot of time to prepare for it. Everything that I've done for this course is nothing compared to what the crew had done for this course. They've been here all the time that I've been here. In addition to that, of course, I'm sure there's a ton of a lot more time that takes to make an edited form of this version. So every single person from the camera crew, to the recording crew, to the makeup crew, to everybody who has been involved in this were just absolutely fantastic. They have been very supporting, very acknowledging, very helping in every single thing that I have done for this course. So my salute to them and I'm very thankful for all their help.


Hey guys, this is Kevin. Today we're going to work on HP OfficeJet 6978 and we're still going to work on the fake paper jam. I already have some other fake paper jam videos how to troubleshoot HP fake paper jam. I'm going to put a link above. If this video doesn't help you solve it, just click the link above and that's the other videos. Okay, after you start, it's going to show this paper jam screen. We have a problem. It's very important to read what our message is. So this doesn't tell much. Just say paper jam, remove any jam paper. If you guys click OK, then you're gonna get this a second error. Let's pause a second. This one give you a little bit more information and that's an original document loaded. The original is jam in the document feeder. Let's check. I don't see anything at all. It's all clean. This is just second part of the error scanner failure. I tell you there's something wrong with the scanner. And then we're here for a treat. We've got three errors in one. There's another error set the printer failure 0x61 000048. Okay, let's summarize what we've seen here. I think this error starts it though. This usually caused by a loose FFC cable from the scanner. So I think you have cable loose. And this usually caused by the cable, the power cable or the FFC cable to the scanner. Because of these errors, the printer wasn't properly shut down. Which caused the printer's waste basket is in a weird position when you power it up. So a guide attached to the printhead. So a printhead cannot move. And that's why I get you this generic paper jam error. Okay, that's probably too boring. Okay, let's fix it. I have a video about the last scenario that you improper shutdown make the waste basket attached to printhead. I'll put a link above and you can check it out how to fix it. But for this one, we're going to fix the scanner first. Okay, let's write to the point. And we need to remove this hinge to open up the scanner. There's no good way to remove it. Just put the force to bend it forward. It's helpful if you have a screwdriver to help you hand just bend it forward and the dog gonna make it detached. After it's detached, have something in the back to hold the scanner straight up. Then you can remove 10 screws. To remove the top cover, there are two taps behind the LCD panel. You need to push them in. Now we can remove the LED panel by this contacting the white cables. And then the top cover can be removed. Oh, by the way, when you connect the FFC, take a look, see where the connection point is. And then when you plug in, make sure the shining part or the iron part is connected to those connected connection points. I can say those two cables wasn't installed correctly. And this is a power cable. When you insert it, it has to click. So when HP installed it, it didn't click. So every time we opened the scanner, I pulled the cable out a little bit. So after I use it for a while, that cable just loose. So I'll put it back. Before we put everything back and double check all the cables are secured and also check the paper tree. When you have the paper tree inserted, you're gonna see that a little lever gonna fall down. And also check this lever. When you raise it up and release it and it should spring back to fall down. Okay, those also look good. And this one look good too. Although we're pretty sure what happened, it was a good practice to service the printer. Just get some alcohol and dab with a paper towel and clean all the rollers. And now we put everything back. Again, make sure you install the cable on the correct side. Put the 10 screws back and then we reattach the hinge for the scanner. It should be able to close gradually like this. And normal errors. So sometime you get a whole bunch of error and it's pretty hard to figure out which error comes first. In this case, the error comes from the scanner. And then I interrupt at the normal start up of the HP. So the scanner error comes first. However, because it is in proper shutdown, you're kind of looping the error into the second loop. And when you restart, the regular paper gem comes first. So it's not always what you see first is the first error. And you can see it because this printer has improper shutdown for a while and the print has already dried. So next video I'm going to show you how to unclog this. Okay, I hope you enjoyed this video. Visit us at www.bchtechnologies.com or locally at Greensboro, North Carolina. Cheers.


Big head here. Oh, it's a nice Laker for sure. Yeah, I'm gonna take it easy. If he don't get his head started, I'm gonna just let him go down. Go to the light. He's got more action. There he comes, right here. He's not as big as the last couple. Sorry, he fought harder than any I've had yet. Nice, look at that Laker after hours guys. Look at that slouched donkey. Beauty. All right, we're gonna, we're gonna probably get him back right away.


What are blocks? As a teacher, you can add blocks to the side of your main learning area. In this course, using the standard boost theme, the blocks are on the right. In this course, with the different standard theme, classic, there are blocks on both sides, and note that the classic theme does not have the nav draw. Check with your admin if your course has a theme different from the two here. Blocks are elements which add extra information or learning content to your course. On small screens, blocks will move down underneath the course section as here. In our Teacher Sam's new course, there are no blocks at the moment, but she can add blocks by turning on the editing and then clicking the add block link in the nav draw. Here, she can add useful blocks to her course. Once added, blocks may be hidden or deleted from the gear or cog menu. They may also be moved around with the crosshairs icon by clicking and holding the crosshairs icon and selecting a location to move them to, or by simply dragging and dropping. Here, for example, Sam is moving the online users block underneath the latest badges block.