当前位置:网站首页>Swift return type is a function of function
Swift return type is a function of function
2022-07-03 12:34:00 【iWillook】
//
// main.swift
// Ultimate
//
// Created by Mewlan Musajan on 3/5/21.
//
import Foundation
func stepForward(_ input: Int) -> Int {
return input + 1
}
func stepBackward(_ input: Int) -> Int {
return input - 1
}
func chooseStepFunction(_ backward: Bool) -> (Int) -> Int {
return backward ? stepBackward : stepForward
}
var currentValue = 3
let moveNearerToZero = chooseStepFunction(currentValue > 0)
print("Counting to zero:")
while currentValue != 0 {
print("\(currentValue)...")
currentValue = moveNearerToZero(currentValue)
}
print("zero!")
边栏推荐
- 在网上炒股开户可以吗?资金安全吗?
- Alibaba is bigger than sending SMS (user microservice - message microservice)
- 102. Sequence traversal of binary tree
- 232. Implement queue with stack
- 145. Post order traversal of binary tree
- If you can't learn, you have to learn. Jetpack compose writes an im app (II)
- 使用BLoC 构建 Flutter的页面实例
- 【ArcGIS自定义脚本工具】矢量文件生成扩大矩形面要素
- LeetCode 0556. Next bigger element III - end of step 4
- Summary of error prone knowledge points: Calculation of define s (x) 3*x*x+1.
猜你喜欢

Cloud Computing future - native Cloud

Shutter: add gradient stroke to font

C language improvement article (wchar_t) character type

【ManageEngine】IP地址扫描的作用

Togaf certification self-study classic v2.0

With pictures and texts, summarize the basic review of C language in detail, so that all kinds of knowledge points are clear at a glance?

QT OpenGL texture map

OpenGL index cache object EBO and lineweight mode

TOGAF认证自学宝典V2.0

Sword finger offer06 Print linked list from end to end
随机推荐
repo Manifest Format
(construction notes) learning experience of MIT reading
(construction notes) learn the specific technology of how to design reusable software entities from three levels: class, API and framework
4000 word super detailed pointer
Introduction to concurrent programming (I)
MySQL time zone solution
Flutter Widget : Flow
[download attached] password acquisition tool lazagne installation and use
Summary of development issues
With pictures and texts, summarize the basic review of C language in detail, so that all kinds of knowledge points are clear at a glance?
Tensorflow binary installation & Failure
239. Sliding window maximum
Togaf certification self-study classic v2.0
Lambda expression
QT OpenGL texture map
使用BLoC 构建 Flutter的页面实例
Wechat applet pages always report errors when sending values to the background. It turned out to be this pit!
JVM内存模型
225. Implement stack with queue
Day 1 of kotlin learning: simple built-in types of kotlin