File: arguments.go

package info (click to toggle)
golang-bugst-f 0.4.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 108 kB
  • sloc: makefile: 2
file content (27 lines) | stat: -rw-r--r-- 634 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
//
// This file is part of go-algorithms.
//
// Copyright 2024 Cristian Maglie. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//

package f

import "fmt"

// Must should be used to wrap a call to a function returning a value and an error.
// Must returns the value if the errors is nil, or panics otherwise.
func Must[T any](val T, err error) T {
	if err != nil {
		panic(err.Error())
	}
	return val
}

// Assert panics if condition is false.
func Assert(condition bool, msg string, args ...any) {
	if !condition {
		panic(fmt.Sprintf(msg, args...))
	}
}