How can I create an operator to implement error chaining?

前端 未结 2 1412
青春惊慌失措
青春惊慌失措 2021-01-29 12:54

I want to implement the following operator »:

throwingFunction(arg: T?)».doStuff()

/*  if throwingFunction throws an error:
     print or log the er         


        
2条回答
  •  花落未央
    2021-01-29 13:11

    prefix and postfix are unary operators i.e. they only accept one operand, whereas an infix operator is a binary operator i.e. it accepts two operands.

    So, static func »(value:key:) -> Preferred? is not correct because it's taking two operands whereas you have defined » as a postfix operator.

提交回复
热议问题