damonchen / o

ternary operator for golang

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

o

ternary operator for golang, only for the same return type

example

import (
	"github.com/damonchen/o"
)

v := o.T(p == nil, "not exist", "exits")

lazy evaluate

import (
	"github.com/damonchen/o"
)

v := o.L(p == nil, o.W("not exist"), o.W("exist"))

complicated example

import (
	"github.com/damonchen/o"
)

v := o.L(p == nil, o.W("unknown"), func() string{
	return o.T(p.gender == 1 ? "man": "women")
})

About

ternary operator for golang

License:Apache License 2.0


Languages

Language:Go 100.0%