lang

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2024 License: MPL-2.0 Imports: 0 Imported by: 0

README

lang

Package lang provides some helpful or at least amusing language features not included in the standard Go language or libraries.

Run CI Tests

Motivation

The helpers provided by package lang are inspired by the lack of some basic language features in the Go language or libraries.

If/Else

Say we want to conditionally set the value of a string - one that could be a const in another language, written only on initialization, but conditionally.

e.g.

final String s = (true) ? "foo" : "bar"

In Go we cannot do this, instead we must write something like,

s := "foo"
if true {
    s = "bar"
}

This grinds my gears. Why waste 4 lines of code on something that could be 1 line?

Now, we can!

s := lang.If(true, "foo").Else("bar")

Contributing

Contributions are welcome! Feel free to help make lang better by filing an issue or opening a PR.

License

The github.com/shoenig/lang module is open source under the MPL-2.0 license.

Documentation

Overview

Package lang provides some helpful or at least amusing language features not included in the standard Go language or libraries.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func If

func If[A any](b bool, v1 A) evaluation[A]

If can be chained together with Else to create type-safe one-line if/else expressions in Go.

e.g.

v := If(expression, value).Else(default)

Types

type Pair added in v0.0.1

type Pair[T, U any] struct {
	A T
	B U
}

A Pair contains two elements of any type(s).

Jump to

Keyboard shortcuts

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