swift swift中的关联附加运算符

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了swift swift中的关联附加运算符相关的知识,希望对你有一定的参考价值。

infix operator <~ { associativity left }

func <~<elem> (var list:[elem], elem:elem) -> [elem] {
    list.append(elem)
    return list
}

[1, 2, 3] <~ 4
//[1, 2, 3, 4]
[1, 2, 3] <~ [5]
//[1, 2, 3, [5]]

//due to associativity being left, the operands are all push to the list on the left
[1] <~ [2] <~ [3]
//[1, [2], [3]]

[1] <~ 2 <~ 3 <~ 5
//[1, 2, 3, 4]

以上是关于swift swift中的关联附加运算符的主要内容,如果未能解决你的问题,请参考以下文章