rese

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2024 License: MIT Imports: 2 Imported by: 6

README

GitHub Workflow Status (branch) GoDoc Coverage Status Supported Go Versions GitHub Release Go Report Card

rese

rese simplifies Go error handling and result extraction for multi-value function calls. It combines error and result checks into a single operation.

rese stands for res (result) + err (error).


CHINESE README

中文说明


Installation

go get github.com/yyle88/rese

Functions

Function Purpose Returns
V0(err error) Checks the error and panics if it's not nil. No return value. None
V1[T1 any](v1 T1, err error) T1 Checks the error, and if no error, returns v1. Returns the value of type T1
V2[T1, T2 any](v1 T1, v2 T2, err error) (T1, T2) Checks the error, and if no error, returns v1 and v2. Returns v1 of type T1 and v2 of type T2
P0(err error) Checks the error and panics if it's not nil. No return value. None
P1[T1 any](v1 *T1, err error) *T1 Checks the error, checks that v1 is non-nil, and returns v1. Returns a pointer to v1 of type T1
P2[T1, T2 any](v1 *T1, v2 *T2, err error) (*T1, *T2) Checks the error, checks that v1 and v2 are non-nil, and returns v1 and v2. Returns pointers to v1 and v2 of types T1 and T2
C0(err error) Checks the error and panics if it's not nil. No return value. None
C1[T1 comparable](v1 T1, err error) T1 Checks the error, checks that v1 is not a zero value, and returns v1. Returns v1 of type T1
C2[T1, T2 comparable](v1 T1, v2 T2, err error) (T1, T2) Checks the error, checks that v1 and v2 are not zero values, and returns v1 and v2. Returns v1 of type T1 and v2 of type T2

Examples

Example 1: Simple error and result checking with V1
package main

import (
	"fmt"
	"github.com/yyle88/rese"
)

func run() (string, error) {
	return "Hello, World!", nil
}

func main() {
	// Using V1 to check for error and get the result
	result := rese.V1(run()) 
	fmt.Println(result) // Outputs: Hello, World!
}
Example 2: Ensuring non-nil pointers with P1
package main

import (
	"fmt"
	"github.com/yyle88/rese"
)

func getSomething() (*int64, error) {
	v := int64(42)
	return &v, nil
}

func main() {
	// Using P1 to check error and ensure non-nil pointer
	ptr := rese.P1(getSomething()) 
	fmt.Println(*ptr) // Outputs: 42
}
Example 3: Zero-value checking with C1
package main

import (
	"fmt"
	"github.com/yyle88/rese"
)

func getInt() (int, error) {
	return 20, nil
}

func main() {
	// Using C1 to check error and ensure non-zero result
	num := rese.C1(getInt())
	fmt.Println("Received:", num) // Outputs: 20
}

License

This project is licensed under the MIT License. See the LICENSE file for details.


Support

Welcome to contribute to this project by submitting pull requests or reporting issues.

If you find this package helpful, give it a star on GitHub!

Thank you for your support!

Happy Coding with rese! 🎉


See stars

see stars


Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func C0

func C0(err error)

func C1

func C1[T1 comparable](v1 T1, err error) T1

func C2

func C2[T1, T2 comparable](v1 T1, v2 T2, err error) (T1, T2)

func C3

func C3[T1, T2, T3 comparable](v1 T1, v2 T2, v3 T3, err error) (T1, T2, T3)

func C4

func C4[T1, T2, T3, T4 comparable](v1 T1, v2 T2, v3 T3, v4 T4, err error) (T1, T2, T3, T4)

func C5

func C5[T1, T2, T3, T4, T5 comparable](v1 T1, v2 T2, v3 T3, v4 T4, v5 T5, err error) (T1, T2, T3, T4, T5)

func C6

func C6[T1, T2, T3, T4, T5, T6 comparable](v1 T1, v2 T2, v3 T3, v4 T4, v5 T5, v6 T6, err error) (T1, T2, T3, T4, T5, T6)

func C7

func C7[T1, T2, T3, T4, T5, T6, T7 comparable](v1 T1, v2 T2, v3 T3, v4 T4, v5 T5, v6 T6, v7 T7, err error) (T1, T2, T3, T4, T5, T6, T7)

func C8

func C8[T1, T2, T3, T4, T5, T6, T7, T8 comparable](v1 T1, v2 T2, v3 T3, v4 T4, v5 T5, v6 T6, v7 T7, v8 T8, err error) (T1, T2, T3, T4, T5, T6, T7, T8)

func C9

func C9[T1, T2, T3, T4, T5, T6, T7, T8, T9 comparable](v1 T1, v2 T2, v3 T3, v4 T4, v5 T5, v6 T6, v7 T7, v8 T8, v9 T9, err error) (T1, T2, T3, T4, T5, T6, T7, T8, T9)

func P0

func P0(err error)

func P1

func P1[T1 any](v1 *T1, err error) *T1

func P2

func P2[T1, T2 any](v1 *T1, v2 *T2, err error) (*T1, *T2)

func P3

func P3[T1, T2, T3 any](v1 *T1, v2 *T2, v3 *T3, err error) (*T1, *T2, *T3)

func P4

func P4[T1, T2, T3, T4 any](v1 *T1, v2 *T2, v3 *T3, v4 *T4, err error) (*T1, *T2, *T3, *T4)

func P5

func P5[T1, T2, T3, T4, T5 any](v1 *T1, v2 *T2, v3 *T3, v4 *T4, v5 *T5, err error) (*T1, *T2, *T3, *T4, *T5)

func P6

func P6[T1, T2, T3, T4, T5, T6 any](v1 *T1, v2 *T2, v3 *T3, v4 *T4, v5 *T5, v6 *T6, err error) (*T1, *T2, *T3, *T4, *T5, *T6)

func P7

func P7[T1, T2, T3, T4, T5, T6, T7 any](v1 *T1, v2 *T2, v3 *T3, v4 *T4, v5 *T5, v6 *T6, v7 *T7, err error) (*T1, *T2, *T3, *T4, *T5, *T6, *T7)

func P8

func P8[T1, T2, T3, T4, T5, T6, T7, T8 any](v1 *T1, v2 *T2, v3 *T3, v4 *T4, v5 *T5, v6 *T6, v7 *T7, v8 *T8, err error) (*T1, *T2, *T3, *T4, *T5, *T6, *T7, *T8)

func P9

func P9[T1, T2, T3, T4, T5, T6, T7, T8, T9 any](v1 *T1, v2 *T2, v3 *T3, v4 *T4, v5 *T5, v6 *T6, v7 *T7, v8 *T8, v9 *T9, err error) (*T1, *T2, *T3, *T4, *T5, *T6, *T7, *T8, *T9)

func V0

func V0(err error)

func V1

func V1[T1 any](v1 T1, err error) T1

func V2

func V2[T1, T2 any](v1 T1, v2 T2, err error) (T1, T2)

func V3

func V3[T1, T2, T3 any](v1 T1, v2 T2, v3 T3, err error) (T1, T2, T3)

func V4

func V4[T1, T2, T3, T4 any](v1 T1, v2 T2, v3 T3, v4 T4, err error) (T1, T2, T3, T4)

func V5

func V5[T1, T2, T3, T4, T5 any](v1 T1, v2 T2, v3 T3, v4 T4, v5 T5, err error) (T1, T2, T3, T4, T5)

func V6

func V6[T1, T2, T3, T4, T5, T6 any](v1 T1, v2 T2, v3 T3, v4 T4, v5 T5, v6 T6, err error) (T1, T2, T3, T4, T5, T6)

func V7

func V7[T1, T2, T3, T4, T5, T6, T7 any](v1 T1, v2 T2, v3 T3, v4 T4, v5 T5, v6 T6, v7 T7, err error) (T1, T2, T3, T4, T5, T6, T7)

func V8

func V8[T1, T2, T3, T4, T5, T6, T7, T8 any](v1 T1, v2 T2, v3 T3, v4 T4, v5 T5, v6 T6, v7 T7, v8 T8, err error) (T1, T2, T3, T4, T5, T6, T7, T8)

func V9

func V9[T1, T2, T3, T4, T5, T6, T7, T8, T9 any](v1 T1, v2 T2, v3 T3, v4 T4, v5 T5, v6 T6, v7 T7, v8 T8, v9 T9, err error) (T1, T2, T3, T4, T5, T6, T7, T8, T9)

Types

This section is empty.

Jump to

Keyboard shortcuts

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