must

package
Version: v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2021 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package 'must' provides another alternative to the 'fluent' package, providing many helpful functions for wrapping methods with multiple returns into a single return (converting errors into panics).

It's useful especially for testing code and other situations where panics are not problematic.

Unlike the 'fluent' package, panics are not of any particular type. There is no equivalent to the `fluent.Recover` feature in the 'must' package.

Because golang supports implied destructuring of multiple-return functions into arguments for another funtion of matching arity, most of the 'must' functions can used smoothly in a pointfree/chainable form, like this:

must.Node(SomeNodeBuilder{}.CreateString("a"))

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Int

func Int(n ld.Node) int64

must.Int unboxes the given Node via AsInt, panicking in the case that the Node isn't of int kind, and otherwise returning the bare native int.

func Node

func Node(n ld.Node, e error) ld.Node

must.Node helps write pointfree/chainable-style code by taking a Node and an error and transforming any error into a panic.

Because golang supports implied destructuring of multiple-return functions into arguments for another funtion of matching arity, it can be used like this:

must.Node(SomeNodeBuilder{}.CreateString("a"))

func NotError

func NotError(e error)

must.NotError simply panics if given an error. It helps turn multi-line code into one-liner code in situations where you simply don't care.

func String

func String(n ld.Node) string

must.String unboxes the given Node via AsString, panicking in the case that the Node isn't of string kind, and otherwise returning the bare native string.

func True

func True(v bool)

must.True panics if the given bool is false.

func TypedNode

func TypedNode(n ld.Node, e error) schema.TypedNode

must.TypedNode helps write pointfree/chainable-style code by taking a Node and an error and transforming any error into a panic. It will also cast the `ld.Node` to a `schema.TypedNode`, panicking if impossible.

Because golang supports implied destructuring of multiple-return functions into arguments for another funtion of matching arity, it can be used like this:

must.TypedNode(SomeNodeBuilder{}.CreateString("a"))

Types

This section is empty.

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL