Discover Packages
github.com/bluescreen10/ternary
package
module
Version:
v1.0.1
Opens a new window with list of versions in this module.
Published: Jan 12, 2023
License: MIT
Opens a new window with license information.
Imports: 0
Opens a new window with list of imports.
Imported by: 0
Opens a new window with list of known importers.
README
README
¶
ternary
Ternary operator for Go
Usage
A ternary operator is a short version of an if-else statement that can make
the code more readable for some use cases such is variable initialization:
import "github.com/bluescreen10/ternary"
function createServer(desiredPort int) {
port := ternary.T( desiredPort > 0, desiredPort, 8080)
// some code
}
Expand ▾
Collapse ▴
Documentation
¶
func T[T any ](cond bool , ifTrue, ifFalse T) T
T creates a ternary expression. The first argument is a bool called cond,
the second is the value that gets returned if cond is true, and the third
argument is the value that gets returned if cond is false.
Source Files
¶
Click to show internal directories.
Click to hide internal directories.