Ehrmm, well, you can do that. The bit that you can't do without it being 
implemented in language is having it behave as a properly type-safe 
expression all the way through.

Here is an example of a ternary function and its use that correctly 
triggers side-effects down only its true path and never calls functions or 
triggers side-effects on the other paths. It is quite a bit more verbose 
than a simple ternary, and I would definitely not recommend its use, but it 
is an interesting example of the use of first-class functions.

https://play.golang.org/p/0PVSeTsQZr

There are two forms there, one that is nestable but is only a statement, 
and can't be used in expression context (but is more compact to write, and 
type-safe). The other is nestable and works as an expression, but uses 
interface{} and so needs casting depending on the use context.

Howard

On Friday, January 13, 2017 at 8:41:54 AM UTC-6, Michael Jones wrote:
>
> One minor point is that you cannot fake the ternary operator with a 
> function. In the function call the two alternates are evaluated before the 
> call so this breaks ... everything else with side effects such as function 
> calls.
>

-- 
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.
For more options, visit https://groups.google.com/d/optout.

Reply via email to