Introduction to Elm, v2 Anonymous Functions
Transcript from the "Anonymous Functions" Lesson
[00:00:23] This is how you define a function in line in Elm without giving it a name. Like we did previously with pluralize. So syntactically, what's going on here is, this little \ is intended to look like a lambda. So lambda is usually the term for functions in a lot of programming languages, and the history of functions in general in math.
[00:00:57] In Elm, it's just a small arrow with a dash instead of an equal sign. Also, if we had multiple arguments here, those would be separated by spaces, just like in a named function, with no commas. This is going to uppercase the string. That's going to add an exclamation point on the end.
[00:01:14] And if we run this, we're gonna get the same thing that we did with the other implementation, POW!, ZAP!, BLAM!. With exclamation points and uppercase. If we tried to make the same mistake as before. We tried to add 500 on there, it's just not gonna compile. We're gonna get this error message at compile time.
[00:01:29] The third and fourth entries in this list are different types of values. Hint, every entry in a list needs to be the same type of value. So this will not compile, that's one of the ways that Elm avoids this particular type of runtime exception.