operator

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: May 17, 2026 License: MIT Imports: 0 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

operator — bitwise & ternary helpers

import "github.com/downsized-devs/sdk-go/operator"

Stability: Stable — see STABILITY.md

Tiny package. Used by codes, errors, audit, tracker.

Features

  • Ternary[T comparable](cond, a, b) T — generic ternary, replaces if-statements inline.
  • CheckBitOnPosition(number, position int) bool — bit-flag test.

Installation

go get github.com/downsized-devs/sdk-go/operator

Quick Start

import "github.com/downsized-devs/sdk-go/operator"

label := operator.Ternary(ok, "yes", "no")
flag  := operator.CheckBitOnPosition(0b1010, 2) // true (2nd bit set)

API Reference

Symbol Signature
Ternary [T comparable](condition bool, a, b T) T
CheckBitOnPosition (number, position int) bool (position is 1-indexed)

Dependencies

stdlib only.

Testing

go test ./operator/...

Contributing

See CONTRIBUTING.md.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckBitOnPosition

func CheckBitOnPosition(number, position int) bool
  1. Left shift given number 1 by position-1 to create a number that has only set bit as position-th bit. temp = 1 << (position-1)
  2. If bitwise AND of number and temp is non-zero, then result is SET else result is NOT SET.

func Ternary

func Ternary[T comparable](condition bool, a, b T) T

Ternary returns a if condition is true, otherwise it returns b.

Types

This section is empty.

Jump to

Keyboard shortcuts

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