No, it is not possible. The *only* functions that can return either one or two returns are builtins. That's because the number of returns is part of the type of a function, so it is constant for every function. Builtin "functions", OTOH, are not really functions, in terms of the language. They are intrinsics of the compiler, which parses the call-expression and translates them into machine code or calls into the runtime (which is also how they can be generic, without Go having generics). You can see that by trying to assign a builtin function to a variable: https://play.golang.org/p/0EiSIIqSLhp This would be possible for every function - but `append` has no type, so you can't put it in a variable (which would need to have the same type as `append`).
What you ask is just categorically impossible in Go. On Fri, Aug 27, 2021 at 5:06 PM Vasiliy Tolstov <v.tols...@selfip.ru> wrote: > I know, so my question is - does it possible to write such functions > like builtin? For example I can create func via reflect.... > > пт, 27 авг. 2021 г. в 18:03, Levieux Michel <mlevieu...@gmail.com>: > > > > Hi, > > > > Optional returns and parameters don't exist in go, what you are > referring to is built-in behavior specific to some features. > > > > A good way to approach what you want is by assigning it to the anonymous > '_' var when you don't want the returned bool. > > > > Hope this helps > > > > Le ven. 27 août 2021 à 16:58, Vasiliy Tolstov <v.tols...@selfip.ru> a > écrit : > >> > >> Does it possible to have own func that have string, bool return value, > >> but bool value optional? > >> Like receiving from channel or get element from map, or like when > >> casting to some type interface? > >> > >> -- > >> Vasiliy Tolstov, > >> e-mail: v.tols...@selfip.ru > >> > >> -- > >> You received this message because you are subscribed to the Google > Groups "golang-nuts" group. > >> To unsubscribe from this group and stop receiving emails from it, send > an email to golang-nuts+unsubscr...@googlegroups.com. > >> To view this discussion on the web visit > https://groups.google.com/d/msgid/golang-nuts/CACaajQvoPEGMM-KB3uRmibXr_HL_aqz_bb2%3DKT%3DsbQKR4U4Gkw%40mail.gmail.com > . > > > > -- > Vasiliy Tolstov, > e-mail: v.tols...@selfip.ru > > -- > You received this message because you are subscribed to the Google Groups > "golang-nuts" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to golang-nuts+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/golang-nuts/CACaajQsJ3KeKMStEWvUYtgGnmZMX1gbq_vbt73k6TM2LTkepUA%40mail.gmail.com > . > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAEkBMfGjdCgLi1L9-SJP2kn%2BixugZ5NSpprerhEXSLqeS%3DXjxA%40mail.gmail.com.