Golang ergonomic declarative generics module inspired by Rust, including Result, Option, and more.

gust Docs

Golang ergonomic declarative generics module inspired by Rust.

Go Version

go≥1.18

Features

Result

Avoid if err != nil, handle result with chain methods.

  • Result Example
func ExampleResult_AndThen() {
	var divide = func(i, j float32) gust.Result[float32] {
		if j == 0 {
			return gust.Err[float32]("j can not be 0")
		}
		return gust.Ok(i / j)
	}
	var ret float32 = divide(1, 2).AndThen(func(i float32) gust.Result[float32] {
		return gust.Ok(i * 10)
	}).Unwrap()
	fmt.Println(ret)
	// Output:
	// 5
}
func ExampleResult_UnwrapOr() {
	const def int = 10

	// before
	i, err := strconv.Atoi("1")
	if err != nil {
		i = def
	}
	fmt.Println(i * 2)

	// now
	fmt.Println(gust.Ret(strconv.Atoi("1")).UnwrapOr(def) * 2)

	// Output:
	// 2
	// 2
}

Option

Avoid (T, bool) and if *U != nil, handle value with Option type.

  • Option Example
func ExampleOption() {
	type A struct {
		X int
	}
	var a = gust.Some(A{X: 1})
	fmt.Println(a.IsSome(), a.IsNone())

	var b = gust.None[A]()
	fmt.Println(b.IsSome(), b.IsNone())

	var x = b.UnwrapOr(A{X: 2})
	fmt.Println(x)

	var c *A
	fmt.Println(gust.Ptr(c).IsNone())
	c = new(A)
	fmt.Println(gust.Ptr(c).IsNone())

	type B struct {
		Y string
	}
	var d = opt.Map(a, func(t A) B {
		return B{
			Y: strconv.Itoa(t.X),
		}
	})
	fmt.Println(d)

	// Output:
	// true false
	// false true
	// {2}
	// true
	// false
	// Some({1})
}
Owner
henrylee2cn
Cease to programing and cease to live.
henrylee2cn
Similar Resources

A API scanner written in GOLANG to scan files recursively and look for API keys and IDs.

GO FIND APIS _____ ____ ______ _____ _ _ _____ _____ _____ _____ / ____|/ __ \ | ____|_ _| \ | | __ \ /\ | __ \_

Oct 25, 2021

Todo-list - In this project using golang and mySql to create todo-list to Add and remove

Todo-list - In this project using golang and mySql to create todo-list to Add and remove

TODO-Fullstack-App-Go-Gin-Postgres-React This fullstack application creates a TODO List Web Page using the Go/Gin/Postgres/React Stack. Starting the a

Apr 7, 2022

Desenvolvendo-Sistema-Planejamento-Financeiro-GoLang - Developing a Financial Planning System with Golang

dio-expert-session-finance Pré Desenvolvimento Vamos criar um projeto no Github

Jan 27, 2022

Golang-action - A template repository for writing custom GitHub Actions in Golang

Golang Action A template repository for writing custom GitHub Actions in Golang.

Feb 12, 2022

Common functional data manipulation and abstraction patterns in Golang.

Functional Patterns in Golang GOMAD (Early stage) This package is still in an early stage of development. Feel free to open a PR and contribute or jus

Jan 8, 2023

I try to make a Restfull-API with golang and interaction with json.file

{ "users": [ { "name": "Elliot", "type": "Reader", "age": 23, "social": { "facebook": "https://facebook.com",

Jan 5, 2022

Simple and fast webp library for golang

Simple and fast webp library for golang

go-webp Golang Webp library for encoding and decoding, using C binding for Google libwebp Requirements libwebp Benchmarks % go test -bench "^Benchmark

Dec 28, 2022

TODO_GO: a simple todo API created in Golang with a minimum number of dependencies and configuration

TODO_GO: a simple todo API created in Golang with a minimum number of dependencies and configuration

TODO_GO TODO_GO is a simple todo API created in Golang with a minimum number of

Jan 1, 2022

Gocaptcha - An API wrapper for popular captcha solvers such as AntiCaptcha and 2Captcha in Golang

An API wrapper for popular captcha solvers such as AntiCaptcha and 2Captcha in Golang

Nov 1, 2022
Comments
  • Add a github action to show the build/test status

    Add a github action to show the build/test status

    Thanks for your work, that's great!

    Maybe we could add a github action ci in this repo. Like this:

    name: Go
    
    on:
      push:
        tags:
        branches:
      pull_request:
    
    jobs:
    
      build:
        runs-on: ubuntu-latest
        steps:
        - uses: actions/checkout@v2
    
        - name: Set up Go
          uses: actions/setup-go@v2
          with:
            go-version: 1.18
            stable: false
      
        - name: Build
          run: make build
    
        - name: Test
          run: make test
    
        - name: Test
          run: make coverage
    
        - name: Codecov
          uses: codecov/codecov-action@v2
          with:
            token: ${{ secrets.CODECOV_TOKEN }}
            file: ./cover.out
            flags: unittests
            verbose: true
    
An experiment which attempts to create streams similar to what is available in Java now that we have generics in Go.

go-streams An experiment which attempts to create streams similar to what is available in Java now that we have generics. Should I use this library? N

Aug 9, 2022
Golang module for working with VK API

VK SDK for Golang VK SDK for Golang ready implementation of the main VK API functions for Go. Russian documentation Features Version API 5.131. API 40

Dec 10, 2022
Amplitude unofficial client for Go, inspired in their official SDK for Node

Amplitude Golang SDK Amplitude unofficial client for Go, inspired in their official SDK for Node. For reference, visit HTTP API v2 documentation. Inst

Dec 31, 2022
starenv allows populating environmental variables from variety of sources, such as AWS Parameter Store, GPG encrypted files and more, with extreme ease.

starenv (*env) allows populating environmental variables from variety of sources, such as AWS Parameter Store, GPG encrypted files and more, with extr

Nov 25, 2022
Dogecoin GigaWallet is a backend service for creating payment platforms, tipping bots, dogecoin exchanges and more.
Dogecoin GigaWallet is a backend service for creating payment platforms, tipping bots, dogecoin exchanges and more.

The Dogecoin GigaWallet is a backend service which provides a convenient integration API for platforms such as online shops, exchanges, social media p

Nov 3, 2022
Go module to work with Postman Collections

go-postman-collection Go module to work with Postman Collections. This module aims to provide a simple way to work with Postman collections. Using thi

Dec 29, 2022
Go module for communicating with the Veryfi OCR API
Go module for communicating with the Veryfi OCR API

veryfi-go is a Go module for communicating with the Veryfi OCR API Installing This package can be installed by cloning this directory: git clone https

Jan 5, 2023
This program performs stress testing for the Cosmos module

Cosmos Modules Testing Program ?? Overview This program performs stress testing for the Cosmos module. Support: Liquidity , IBC transfer Note: Require

May 25, 2022
A Lambda function built with SAM (Serverless Application Module)

AWS SAM Lambda Function © Israel Pereira Tavares da Silva The AWS Serverless Application Model (SAM) is an open-source framework for building serverle

Dec 19, 2021
Client-server-golang-sqs - Client Server with SQS and golang

Client Server with SQS and golang Multi-threaded client-server demo with Go What

Feb 14, 2022