goidiomatic

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2023 License: MIT Imports: 7 Imported by: 0

README

Go Idiomatic

go_idiomatic provides a Starlark module that defines Go idiomatic functions and values.

Functions

length(obj) int

Returns the length of the object, for string it returns the number of Unicode code points, instead of bytes like len().

Examples

String

Calculate the length of a CJK string.

load("go_idiomatic", "length")
s = "你好"
print(length(s), len(s))
# Output: 2 6

Misc

Calculate the length of a list, set and map.

load("go_idiomatic", "length")
print(length([1, 2, 3]), length(set([1, 2])), length({1: 2}))
# Output: 3 2 1
sum(iterable, start=0)

Returns the sum of start and the items of an iterable from left to right. The iterable's items and the start value are normally numbers.

Examples

Basic

Calculate the sum of a list.

load("go_idiomatic", "sum")
print(sum([1, 2, 3]))
# Output: 6

Start

Calculate the sum of a list with a start value.

load("go_idiomatic", "sum")
print(sum([1, 2, 3], 10))
# Output: 16
sleep(secs)

Sleeps for the given number of seconds.

Examples

Basic

Sleep for 1 second.

load("go_idiomatic", "sleep")
sleep(1)
exit(code=0)

Exits the program with the given exit code.

Examples

Default

Exit with default code (0).

load("go_idiomatic", "exit")
exit()

Non-zero

Exit with code 1.

load("go_idiomatic", "exit")
exit(1)
quit(code=0)

Alias for exit().

Examples

Default

Exit with default code (0).

load("go_idiomatic", "quit")
quit()

Non-zero

Exit with code 1.

load("go_idiomatic", "quit")
quit(1)

Types

nil

Value as an alias for None.

true

Value as an alias for True.

false

Value as an alias for False.

Documentation

Overview

Package goidiomatic provides a Starlark module that defines Go idiomatic functions and values.

Index

Constants

View Source
const ModuleName = "go_idiomatic"

ModuleName defines the expected name for this Module when used in Starlark's load() function, eg: load('go_idiomatic', 'nil')

Variables

View Source
var (
	// ErrSystemExit is returned by exit() to indicate the program should exit.
	ErrSystemExit = errors.New(`starlet runtime system exit (Use Ctrl-D in REPL to exit)`)
)

Functions

func LoadModule

func LoadModule() (starlark.StringDict, error)

LoadModule loads the Go idiomatic module.

Types

This section is empty.

Jump to

Keyboard shortcuts

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