From the course: Learning Higher-Order Functions with Swift

Unlock the full course today

Join today to access over 22,400 courses taught by industry experts or purchase this course individually.

Other higher-order functions

Other higher-order functions

From the course: Learning Higher-Order Functions with Swift

Start my 1-month free trial

Other higher-order functions

- [Instructor] Now we're going to talk about a few other higher order functions that may not need as much attention. First, we're going to talk about First. So First returns the first item to match your criteria. So let's say we want to look for the first item that is longer than four characters. I'm sorry if that's a boring example. I know it, but I'm trying to focus on the concept and not get too muddled down in the actual functionality of it. I'll let you apply it to more complicated examples. So, let's say we'll call our result, Let FirstLongName equal names.first, and you have this where clause, more or less. It takes a string and returns a bool. The first thing that passes is going to return True and that's where it stops. So it takes a name. I'll call it Val1 and it returns a bool and I'll just return Val1.count, greater than four. So the first one that's greater than four will be assigned to FirstLong and I'll print that out. So now when I run it, it should print out an…

Contents