ternary

package module
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 12, 2023 License: MIT Imports: 0 Imported by: 0

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
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func T

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.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL