Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use swift functional programming

Shulou Source: shulou.com Published: 2022-06-03 05:51:39 10月14日 Update

This article focuses on "how to use swift functional programming", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to use swift functional programming.

Example / Statistical word frequency let non_words: Set = ["the", "and", "of", "to", "a", "I", "it", "in", "or", "is", "as", "so", "but", "be" "don't"] / / conventional func wordFreq (words: String)-> [Dictionary] {var wordDict: [String: Int] = [:] let wordList = words.split (separator: ") for word in wordList {let lowerCaseWord = word.lowercased () if! non_words.contains (lowerCaseWord) {if let count = wordDict [lowerCaseWord] {wordDict [ LowerCaseWord] = count + 1} else {wordDict [lowerCaseWord] = 1}} var sortedResult = [Dictionary] () for item in wordDict.sorted {$0.1 > $1.1} {sortedResult.append ([item.key: item.value])} return sortedResult} let words = "" The powerful programming language that is also easy to learn Swift is a powerful and Intuitive programming language for macOS iOS watchOS tvOS and beyond Writing Swift code is interactive and fun the syntax is concise yet expressive and Swift includes modern features developers love Swift code is safe by design yet also produces software that runs lightning-fast Swift is the result of the latest research on programming languages combined with decades of experience building Apple platforms Named parameters are expressed in a clean syntax that makes APIs "" let ret = wordFreq (words: words) print (ret) / / ["swift": 5] ["programming": 3], ["that": 3], ["syntax": 2], ["code": 2], ["yet": 2], ["powerful": 2], ["also": 2], ["language": 2], ["beyond": 1], ["clean": 1], ["result": 1], ["features": 1], ["on": 1], ["produces": 1] ["concise": 1], ["latest": 1], ["developers": 1], ["for": 1], ["design": 1], ["experience": 1], ["with": 1], [parameters ": 1], [" building ": 1], [" macos ": 1], [" combined ": 1], [" languages ": 1], [" lightning-fast ": 1], [" tvos ": 1] ["interactive": 1], ["safe": 1], ["fun": 1], ["apis": 1], ["easy": 1], ["decades": 1], ["makes": 1], [by ": 1], [" includes ": 1], [" expressed ": 1], [" love ": 1], [" are ": 1], [" intuitive ": 1], [" named ": 1] ["research": 1], ["writing": 1], ["watchos": 1], ["expressive": 1], ["apple": 1], ["platforms": 1], ["learn": 1], ["ios": 1], ["software": 1], ["modern": 1] ["runs": 1]] / / functional programming func wordFreqTwo (words: String)-> [Dictionary] {var wordDict: [String: Int] = [:] words.split (separator: ") .map {$0.lowercased ()} .filter {! non_words.contains ($0)} .forEach {(word) in wordDict [word] = (wordDict [word) ]? 0) + 1} var sortedResult = [Dictionary] () wordDict.sorted {(word) in sortedResult.append ([word.key: word.value])} return sortedResult} let retTwo = wordFreqTwo (words: words) print (retTwo) / / ["swift": 5] ["programming": 3], ["that": 3], ["syntax": 2], ["also": 2], ["language": 2], ["powerful": 2], ["yet": 2], ["code": 2], ["love": 1], ["safe": 1], ["watchos": 1], ["ios": 1], ["combined": 1], ["tvos": 1] ["runs": 1], ["are": 1], ["experience": 1], ["design": 1], ["by": 1], ["expressed": 1], ["features": 1], [result ": 1], [" parameters ": 1], [" expressive ": 1], [" building ": 1], [" fun ": 1], [" software ": 1], [" on ": 1] ["research": 1], ["writing": 1], ["produces": 1], ["with": 1], ["clean": 1], ["platforms": 1], ["named": 1], [concise ": 1], [" latest ": 1], [" makes ": 1], [" interactive ": 1], [" languages ": 1], [" easy ": 1], [" for ": 1] ["lightning-fast": 1], ["beyond": 1], ["decades": 1], ["apis": 1], ["learn": 1], ["includes": 1], ["modern": 1], ["macos": 1], ["intuitive": 1], ["developers": 1]] so far I believe you have a deeper understanding of "how to use swift functional programming". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Function programming content way learning practical deeper interest practicality practical routine simple operation method more friends examples website word frequency channel query Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn Apple OPPO Reno Huawei Microsoft