RUVIDEO
Поделитесь видео 🙏

Learn Elixir: Keeping Flow Clean

📁 Лайфстайл 👁️ 18 📅 04.12.2023

Learn Elixir In 12 Weeks: https://learn-elixir.dev/

Level 2.4: Keep your functional flow clean and other great Elixir programming practices.


Transcript:
Hello and welcome to Learn Elixir Week two, module four. In this video we're going to be going over keeping your functional flow clean and making sure that your code stays clean amongst multiple functions and different types of control flow. So there are a few types of control flow in elixir. The first we'll start off with his case. Case is very similar to Java script switch condition and allows you to define a case that takes in a parameter and multiple declarations for what should match that parameter if is like in any other language we have if and else we don't have if else and else if however, and that's unlike javascript, we also have, unless I don't recommend you use unless I rarely see this used and feel like it's kind of hard to follow and a lot of other people seem to agree with that so it hardly gets used in Elixir, we also have cond, cond allows you to define multiple match cases and it's a bit like case. However, each condition that you're defining is actually a function as well and you can do whatever you want. Inside of that we also have width, which is similar to case except we're allowed to match multiple things at once. So it's very good for say standing network requests and responding to them where we have a chain of things that could fail, we can use with the other way that we can control the flow of our programs is by using functional declaration with different parameters. And we've seen a bunch of examples of that. But for now let's go over some examples of the other control flow. So let's start off by making our module and we'll just make our module called clean flow. Inside of this we can have a function which we name if and else to represent if and else and just change this to value. So with our value then we can do if value and we actually don't need these brackets here and we can then type else and say else. If it's the value then we'll just say true. We can also create a function called case and that was taken a value and run it against the case statement. So here we say case and pass in the value. And then and and here we can use any sort of pattern matching to actually pull out our value. So we could for example, say value and set it to equal a map. And if that equals a map we'll say value was a map. We can also do the same thing with list and say value equals this list. In this case we don't actually have to do this and same with this. In this case we can actually just leave it as an empty map. And so this one we would say value was an empty list. We can also put it as head and tail and say that the value was a list because we're not using these, we can change these both the underscores. Finally we can have our fall through case and say true and then say value fell through. One thing we'll briefly mention and talk about is guards. So with guards you can actually match more things inside of a pattern match. In here, we can actually x when is list x and now will match any list that is impossible to matching here and we don't need to have that second case. And we can also just say this is the list. The other thing with guards is anything that is prefixed with is he's actually a guard in Elixir. Anything that we prefixed with is, is expected to be a guard. So when you have a function that returns a bullion, what our preferences to do is actually add a question mark after it. So for example, if this returned a boolean such as true and false, we would actually just add a question mark at the end and that would signify that we're returning a boolean value. So inside of this case we can also have guards as a part of the function itself. And so we could say when value equals okay Matt. And so this isn't a quality check against an empty map, which means that value would have to be an empty map. And this is actually how you would check for an empty map in a function that would get called. Because if we did just an empty map here, this actually would catch any type of maps that existed. So we can also have a final one. Uh, cond. So with our con, we can take in a value again, except in this case our cond do an end takes in either functions or [inaudible] quality checks to make sure that it works and it evaluates based off of whether or not the result is true or false. So for example, if we had value equals one, then we could say the value was one.....

Что делает видео по-настоящему запоминающимся? Наверное, та самая атмосфера, которая заставляет забыть о времени. Когда вы заходите на RUVIDEO, чтобы посмотреть онлайн «Learn Elixir: Keeping Flow Clean», вы рассчитываете на нечто большее, чем просто загрузку плеера. И мы это понимаем. Контент такого уровня заслуживает того, чтобы его смотрели в HD 1080, без дрожания картинки и бесконечного буферизации.

Честно говоря, Rutube сегодня — это кладезь уникальных находок, которые часто теряются в общем шуме. Мы же вытаскиваем на поверхность самое интересное. Будь то динамичный экшн, глубокий разбор темы от любимого автора или просто уютное видео для настроения — всё это доступно здесь бесплатно и без лишних формальностей. Никаких «заполните анкету, чтобы продолжить». Только вы, ваш экран и качественный поток.

Если вас зацепило это видео, не забудьте взглянуть на похожие материалы в блоке справа. Мы откалибровали наши алгоритмы так, чтобы они подбирали контент не просто «по тегам», а по настроению и смыслу. Ведь в конечном итоге, онлайн-кинотеатр — это не склад файлов, а место, где каждый вечер можно найти свою историю. Приятного вам отдыха на RUVIDEO!

Видео взято из открытых источников Rutube. Если вы правообладатель, обратитесь к первоисточнику.