zoukankan      html  css  js  c++  java
  • Shorthand Argument Names $0 : 只用于指代Closer声明中的形参

    Shorthand Argument Names

    Swift automatically provides shorthand argument names to inline closures, which can be used to refer to the values of the closure’s arguments by the names $0$1$2, and so on.

    If you use these shorthand argument names within your closure expression, you can omit the closure’s argument list from its definition, and the number and type of the shorthand argument names will be inferred from the expected function type. The in keyword can also be omitted, because the closure expression is made up entirely of its body:

    1. reversedNames = names.sorted(by: { $0 > $1 } )

    Here, $0 and $1 refer to the closure’s first and second String arguments.

    https://docs.swift.org/swift-book/LanguageGuide/Closures.html#ID97

    public func map<U>(_ transform: (Value) -> U) -> Result<U, Error> {

    return flatMap { .success(transform($0)) }

    }

    指代flatMap<U>(_ transform: (Value) -> Result<U, Error>) -> Result<U, Error>中的(Value)

    /// Returns the result of applying `transform` to `Success`es’ values, or re-wrapping `Failure`’s errors.

    public func flatMap<U>(_ transform: (Value) -> Result<U, Error>) -> Result<U, Error> {

    return analysis(

    ifSuccess: transform,

    ifFailure: Result<U, Error>.failure)

    }

  • 相关阅读:
    List,Set,Map初级学习
    String,StringBuffer,StringBuilder 的使用
    activity跳转
    JSON与List之间的转换
    子线程更新UI
    数据库查询关键字显示所有结果
    Java数据类型转换1
    git 操作
    MySql导出表结构
    springBoot双数据源配置
  • 原文地址:https://www.cnblogs.com/feng9exe/p/9765515.html
Copyright © 2011-2022 走看看