当前位置:网站首页>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!")
边栏推荐
- Day 1 of kotlin learning: simple built-in types of kotlin
- Apache Mina Development Manual
- Sword finger offer09 Implementing queues with two stacks
- OpenGL draws colored triangles
- 20. Valid brackets
- 232. Implement queue with stack
- (construction notes) ADT and OOP
- Tensorflow binary installation & Failure
- 2021 autumn Information Security Experiment 1 (password and hiding technology)
- elastic_ L01_ summary
猜你喜欢
Itext7 uses iexternalsignature container for signature and signature verification
Use Tencent cloud IOT platform to connect custom esp8266 IOT devices (realized by Tencent continuous control switch)
OpenGL draws colored triangles
Prompt unread messages and quantity before opening chat group
剑指Offer10- I. 斐波那契数列
云计算未来 — 云原生
剑指Offer06. 从尾到头打印链表
Pki/ca and digital certificate
QT OpenGL texture map
Take you to the installation and simple use tutorial of the deveco studio compiler of harmonyos to create and run Hello world?
随机推荐
If you can't learn, you have to learn. Jetpack compose writes an im app (I)
The difference between lambda and anonymous inner class
DEJA_ Vu3d - cesium feature set 053 underground mode effect
Flutter Widget : Flow
剑指Offer05. 替换空格
error: expected reference but got (raw string)
OpenGL draws colored triangles
What is more elegant for flutter to log out and confirm again?
Applet wxss introduction
Flutter Widget : KeyedSubtree
Airflow installation jump pit
02_ Lock the code, and don't let the "lock" become a worry
Apache Mina Development Manual
Dart: about grpc (I)
(construction notes) grasp learning experience
2021 autumn Information Security Experiment 1 (password and hiding technology)
云计算未来 — 云原生
Flinksql can directly create tables and read MySQL or Kafka data on the client side, but how can it automatically flow and calculate?
232. Implement queue with stack
(construction notes) learning experience of MIT reading