Variable number of return variables in function in Go

后端 未结 1 1090
眼角桃花
眼角桃花 2021-01-22 12:04

I wonder if there is a way to implement a function that behaves similar to map getter: it returns return value as first argument and (optionally assigned) second value ok<

1条回答
  •  盖世英雄少女心
    2021-01-22 12:48

    No, it can't be done, the only option is to return a pointer and check if it's nil.

    if v := f(10); v != nil {
         //stuff
    }
    

    0 讨论(0)
提交回复
热议问题