当前位置:网站首页>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!")
边栏推荐
- Dart: About zone
- 剑指Offer04. 二维数组中的查找【中等】
- Integer int compare size
- Sword finger offer09 Implementing queues with two stacks
- elastic_ L02_ install
- 102. Sequence traversal of binary tree
- Integer string int mutual conversion
- Summary of error prone knowledge points: Calculation of define s (x) 3*x*x+1.
- What is more elegant for flutter to log out and confirm again?
- Alibaba is bigger than sending SMS (user microservice - message microservice)
猜你喜欢

Use Tencent cloud IOT platform to connect custom esp8266 IOT devices (realized by Tencent continuous control switch)

Display time with message interval of more than 1 minute in wechat applet discussion area

剑指Offer06. 从尾到头打印链表

Sword finger offer09 Implementing queues with two stacks

【ArcGIS自定义脚本工具】矢量文件生成扩大矩形面要素

云计算未来 — 云原生

C language improvement article (wchar_t) character type

LeetCode 0556.下一个更大元素 III - 4步讲完

If you can't learn, you have to learn. Jetpack compose writes an im app (I)

ES6 standard
随机推荐
2021 autumn Information Security Experiment 1 (password and hiding technology)
剑指Offer05. 替换空格
启用MemCached的SASL认证
阿里大于发送短信(用户微服务--消息微服务)
regular expression
【ArcGIS自定义脚本工具】矢量文件生成扩大矩形面要素
Sword finger offer05 Replace spaces
error: expected reference but got (raw string)
Adult adult adult
DEJA_ Vu3d - 054 of cesium feature set - simulate the whole process of rocket launch
Adult adult adult
Develop plug-ins for idea
Itext7 uses iexternalsignature container for signature and signature verification
Lambda表达式
Use bloc to build a page instance of shutter
OpenGL index cache object EBO and lineweight mode
01_ Using the concurrent tool class library, is thread safety safe
elastic_ L02_ install
[download attached] password acquisition tool lazagne installation and use
Pki/ca and digital certificate