swift高阶函数全排列
As a swift developer, you must know about higher-order functions. It will speed up your software development skills.
作为一名Swift的开发人员,您必须了解高阶函数。 它将加快您的软件开发技能。
A higher-order function is a function that takes one or more functions as arguments or returns a function as its result. Here are some swift higher-order functions — forEach, map, CompactMap, flatMap, filter, reduce, sort, and sorted.
高阶函数是将一个或多个函数作为参数或返回一个函数作为其结果的函数。 这是一些快速的高阶函数-forEach,map,CompactMap,flatMap,filter,reduce,sort和sorted。
In this article, you will explore the implementation of mostly all types of higher-order functions of swift.
在本文中,您将探索swift几乎所有类型的高阶函数的实现。
Let’s start -
开始吧 -
每次 (ForEach)
forEach will iterate through all elements in an array and will not return anything.
forEach将遍历数组中的所有元素,并且将不返回任何内容。
If you run the above code then the output will look like this —
如果运行上面的代码,则输出将如下所示:
In the above code, in step 1 you are creating an array with name coins.
在上面的代码中,在步骤1中,您将创建一个带有名称硬币的数组。
In step 2, you are iterating through all coins and adding $ to every element and prints it.
在步骤2中,您要遍历所有硬币并将$添加到每个元素并进行打印。
In step 3, you are using forEach for iterating through all coins and adding $ to every element and prints it.
在第3步中,您将使用forEach遍历所有硬币并将$添加到每个元素并进行打印。
In step 4, you are using a short syntax of forEach.
在步骤4中,您使用的是forEach的简短语法。
“forEach” works like “for in” but the basic difference is, you can’t use break and continue statement to exit from th