Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions goutil/utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package goutils

import "fmt"

// Assert panics if the condition is FALSE.
func Assert(condition bool, message string, args ...interface{}) {
if !condition {
panic(fmt.Sprintf("assertion failed: "+message, args...))
}
}

// Lowkey gonna make a result type
type Result[T any] struct {
Val T
Err error
}

func (r Result[T]) Unwrap() T {
if r.Err != nil {
panic(r.Err)
}
return r.Val
}

func Err[T any](err error) Result[T] {
return Result[T]{
Err: err,
}
}

func Ok[T any](val T) Result[T] {
return Result[T]{
Val: val,
Err: nil,
}
}
Loading