Thanks for using Compiler Explorer
Sponsors
Jakt
C++
Ada
Analysis
Android Java
Android Kotlin
Assembly
C
C3
Carbon
C++ (Circle)
CIRCT
Clean
CMake
CMakeScript
COBOL
C++ for OpenCL
MLIR
Cppx
Cppx-Blue
Cppx-Gold
Cpp2-cppfront
Crystal
C#
CUDA C++
D
Dart
Elixir
Erlang
Fortran
F#
GLSL
Go
Haskell
HLSL
Hook
Hylo
IL
ispc
Java
Julia
Kotlin
LLVM IR
LLVM MIR
Modula-2
Nim
Objective-C
Objective-C++
OCaml
Odin
OpenCL C
Pascal
Pony
Python
Racket
Ruby
Rust
Snowball
Scala
Slang
Solidity
Spice
SPIR-V
Swift
LLVM TableGen
Toit
TypeScript Native
V
Vala
Visual Basic
Vyper
WASM
Zig
Javascript
GIMPLE
Ygen
go source #1
Output
Compile to binary object
Link to binary
Execute the code
Intel asm syntax
Demangle identifiers
Verbose demangling
Filters
Unused labels
Library functions
Directives
Comments
Horizontal whitespace
Debug intrinsics
Compiler
ARM gc (tip)
ARM gc 1.14
ARM gc 1.15
ARM gc 1.16
ARM gc 1.17
ARM gc 1.18
ARM gc 1.19
ARM gc 1.20
ARM gc 1.21
ARM gc 1.22.1
ARM gc 1.23.2
ARM gccgo 12.2.0
ARM gccgo 12.3.0
ARM gccgo 12.4.0
ARM gccgo 13.1.0
ARM gccgo 13.2.0
ARM gccgo 13.3.0
ARM gccgo 14.1.0
ARM gccgo 14.2.0
ARM64 gc (tip)
ARM64 gc 1.14
ARM64 gc 1.15
ARM64 gc 1.16
ARM64 gc 1.17
ARM64 gc 1.18
ARM64 gc 1.19
ARM64 gc 1.20
ARM64 gc 1.21
ARM64 gc 1.22.1
ARM64 gc 1.23.2
ARM64 gccgo 12.2.0
ARM64 gccgo 12.3.0
ARM64 gccgo 12.4.0
ARM64 gccgo 13.1.0
ARM64 gccgo 13.2.0
ARM64 gccgo 13.3.0
ARM64 gccgo 14.1.0
ARM64 gccgo 14.2.0
MIPS gc (tip)
MIPS gc 1.14
MIPS gc 1.15
MIPS gc 1.16
MIPS gc 1.17
MIPS gc 1.18
MIPS gc 1.19
MIPS gc 1.20
MIPS gc 1.21
MIPS gc 1.22.1
MIPS gc 1.23.2
MIPS gccgo 12.2.0
MIPS gccgo 12.3.0
MIPS gccgo 12.4.0
MIPS gccgo 13.1.0
MIPS gccgo 13.2.0
MIPS gccgo 13.3.0
MIPS gccgo 14.1.0
MIPS gccgo 14.2.0
MIPS64 gc (tip)
MIPS64 gc 1.14
MIPS64 gc 1.15
MIPS64 gc 1.16
MIPS64 gc 1.17
MIPS64 gc 1.18
MIPS64 gc 1.19
MIPS64 gc 1.20
MIPS64 gc 1.21
MIPS64 gc 1.22.1
MIPS64 gc 1.23.2
MIPS64 gccgo 12.2.0
MIPS64 gccgo 12.3.0
MIPS64 gccgo 12.4.0
MIPS64 gccgo 13.1.0
MIPS64 gccgo 13.2.0
MIPS64 gccgo 13.3.0
MIPS64 gccgo 14.1.0
MIPS64 gccgo 14.2.0
MIPS64EL gccgo 12.2.0
MIPS64EL gccgo 12.3.0
MIPS64EL gccgo 12.4.0
MIPS64EL gccgo 13.1.0
MIPS64EL gccgo 13.2.0
MIPS64EL gccgo 13.3.0
MIPS64EL gccgo 14.1.0
MIPS64EL gccgo 14.2.0
MIPS64LE gc (tip)
MIPS64LE gc 1.14
MIPS64LE gc 1.15
MIPS64LE gc 1.16
MIPS64LE gc 1.17
MIPS64LE gc 1.18
MIPS64LE gc 1.19
MIPS64LE gc 1.20
MIPS64LE gc 1.21
MIPS64LE gc 1.22.1
MIPS64LE gc 1.23.2
MIPSEL gccgo 12.2.0
MIPSEL gccgo 12.3.0
MIPSEL gccgo 12.4.0
MIPSEL gccgo 13.1.0
MIPSEL gccgo 13.2.0
MIPSEL gccgo 13.3.0
MIPSEL gccgo 14.1.0
MIPSEL gccgo 14.2.0
MIPSLE gc (tip)
MIPSLE gc 1.14
MIPSLE gc 1.15
MIPSLE gc 1.16
MIPSLE gc 1.17
MIPSLE gc 1.18
MIPSLE gc 1.19
MIPSLE gc 1.20
MIPSLE gc 1.21
MIPSLE gc 1.22.1
MIPSLE gc 1.23.2
POWER gccgo 12.2.0
POWER gccgo 12.3.0
POWER gccgo 12.4.0
POWER gccgo 13.1.0
POWER gccgo 13.2.0
POWER gccgo 13.3.0
POWER gccgo 14.1.0
POWER gccgo 14.2.0
POWER64 gc (tip)
POWER64 gc 1.14
POWER64 gc 1.15
POWER64 gc 1.16
POWER64 gc 1.17
POWER64 gc 1.18
POWER64 gc 1.19
POWER64 gc 1.20
POWER64 gc 1.21
POWER64 gc 1.22.1
POWER64 gc 1.23.2
POWER64 gccgo 12.2.0
POWER64 gccgo 12.3.0
POWER64 gccgo 12.4.0
POWER64 gccgo 13.1.0
POWER64 gccgo 13.2.0
POWER64 gccgo 13.3.0
POWER64 gccgo 14.1.0
POWER64 gccgo 14.2.0
POWER64 gccgo AT12.0
POWER64 gccgo AT13.0
POWER64 gccgo trunk
POWER64LE gc (tip)
POWER64LE gc 1.14
POWER64LE gc 1.15
POWER64LE gc 1.16
POWER64LE gc 1.17
POWER64LE gc 1.18
POWER64LE gc 1.19
POWER64LE gc 1.20
POWER64LE gc 1.21
POWER64LE gc 1.22.1
POWER64LE gc 1.23.2
POWER64LE gccgo 12.2.0
POWER64LE gccgo 12.3.0
POWER64LE gccgo 12.4.0
POWER64LE gccgo 13.1.0
POWER64LE gccgo 13.2.0
POWER64LE gccgo 13.3.0
POWER64LE gccgo 14.1.0
POWER64LE gccgo 14.2.0
POWER64LE gccgo AT12.0
POWER64LE gccgo AT13.0
POWER64LE gccgo trunk
RISC-V 64 gc (tip)
RISC-V 64 gc 1.14
RISC-V 64 gc 1.15
RISC-V 64 gc 1.16
RISC-V 64 gc 1.17
RISC-V 64 gc 1.18
RISC-V 64 gc 1.19
RISC-V 64 gc 1.20
RISC-V 64 gc 1.21
RISC-V 64 gc 1.22.1
RISC-V 64 gc 1.23.2
RISC-V 64 gccgo 12.2.0
RISC-V 64 gccgo 12.3.0
RISC-V 64 gccgo 12.4.0
RISC-V 64 gccgo 13.1.0
RISC-V 64 gccgo 13.2.0
RISC-V 64 gccgo 13.3.0
RISC-V 64 gccgo 14.1.0
RISC-V 64 gccgo 14.2.0
S390X gc (tip)
S390X gc 1.14
S390X gc 1.15
S390X gc 1.16
S390X gc 1.17
S390X gc 1.18
S390X gc 1.19
S390X gc 1.20
S390X gc 1.21
S390X gc 1.22.1
S390X gc 1.23.2
S390X gccgo 12.2.0
S390X gccgo 12.3.0
S390X gccgo 12.4.0
S390X gccgo 13.1.0
S390X gccgo 13.2.0
S390X gccgo 13.3.0
S390X gccgo 14.1.0
S390X gccgo 14.2.0
SPARC gccgo 12.2.0
SPARC gccgo 12.3.0
SPARC gccgo 12.4.0
SPARC gccgo 13.1.0
SPARC gccgo 13.2.0
SPARC gccgo 13.3.0
SPARC gccgo 14.1.0
SPARC gccgo 14.2.0
SPARC64 gccgo 12.2.0
SPARC64 gccgo 12.3.0
SPARC64 gccgo 12.4.0
SPARC64 gccgo 13.1.0
SPARC64 gccgo 13.2.0
SPARC64 gccgo 13.3.0
SPARC64 gccgo 14.1.0
SPARC64 gccgo 14.2.0
WASM gc (tip)
WASM gc 1.14
WASM gc 1.15
WASM gc 1.16
WASM gc 1.17
WASM gc 1.18
WASM gc 1.19
WASM gc 1.20
WASM gc 1.21
WASM gc 1.22.1
WASM gc 1.23.2
x86 gc (tip)
x86 gc 1.14
x86 gc 1.15
x86 gc 1.16
x86 gc 1.17
x86 gc 1.18
x86 gc 1.19
x86 gc 1.20
x86 gc 1.21
x86 gc 1.22.1
x86 gc 1.23.2
x86 gccgo 10.2.0
x86 gccgo 10.5.0
x86 gccgo 11.1.0
x86 gccgo 11.2.0
x86 gccgo 11.3.0
x86 gccgo 11.4.0
x86 gccgo 12.1.0
x86 gccgo 12.2.0
x86 gccgo 12.3.0
x86 gccgo 12.4.0
x86 gccgo 13.1
x86 gccgo 13.2
x86 gccgo 13.3
x86 gccgo 14.1
x86 gccgo 14.2
x86 gccgo 4.9.4
x86 gccgo 6.3.0
x86 gccgo 7.2.0
x86 gccgo 8.3.0
x86 gccgo 9.3.0
x86 gccgo 9.5.0
x86-64 gc (tip)
x86-64 gc 1.10
x86-64 gc 1.10.1
x86-64 gc 1.11
x86-64 gc 1.12
x86-64 gc 1.13
x86-64 gc 1.14
x86-64 gc 1.15
x86-64 gc 1.16
x86-64 gc 1.17
x86-64 gc 1.18
x86-64 gc 1.19
x86-64 gc 1.20
x86-64 gc 1.21
x86-64 gc 1.22.1
x86-64 gc 1.23.2
x86-64 gc 1.4.1
x86-64 gc 1.7.2
x86-64 gc 1.8.5
x86-64 gc 1.8.7
x86-64 gc 1.9.2
x86-64 gc 1.9.4
Options
Source code
// Type your code here, or load an example. // Your function name should start with a capital letter. package main import "fmt" func Unwrap1[T any, E comparable](x func() (T, E)) T { var Nil E ret, err := x() if err != Nil { panic(err) } return ret } func Unwrap2[T1, T2 any, E comparable](x func() (T1, T2, E)) (T1, T2) { var Nil E ret1, ret2, err := x() if err != Nil { panic(err) } return ret1, ret2 } func Unwrap3[T1, T2, T3 any, E comparable](x func() (T1, T2, T3, E)) (T1, T2, T3) { var Nil E ret1, ret2, ret3, err := x() if err != Nil { panic(err) } return ret1, ret2, ret3 } func Unwrap4[T1, T2, T3, T4 any, E comparable](x func() (T1, T2, T3, T4, E)) (T1, T2, T3, T4) { var Nil E ret1, ret2, ret3, ret4, err := x() if err != Nil { panic(err) } return ret1, ret2, ret3, ret4 } func Unwrap5[T1, T2, T3, T4, T5 any, E comparable](x func() (T1, T2, T3, T4, T5, E)) (T1, T2, T3, T4, T5) { var Nil E ret1, ret2, ret3, ret4, ret5, err := x() if err != Nil { panic(err) } return ret1, ret2, ret3, ret4, ret5 } func Unwrap6[T1, T2, T3, T4, T5, T6 any, E comparable](x func() (T1, T2, T3, T4, T5, T6, E)) (T1, T2, T3, T4, T5, T6) { var Nil E ret1, ret2, ret3, ret4, ret5, ret6, err := x() if err != Nil { panic(err) } return ret1, ret2, ret3, ret4, ret5, ret6 } func Unwrap7[T1, T2, T3, T4, T5, T6, T7 any, E comparable](x func() (T1, T2, T3, T4, T5, T6, T7, E)) (T1, T2, T3, T4, T5, T6, T7) { var Nil E ret1, ret2, ret3, ret4, ret5, ret6, ret7, err := x() if err != Nil { panic(err) } return ret1, ret2, ret3, ret4, ret5, ret6, ret7 } func Unwrap8[T1, T2, T3, T4, T5, T6, T7, T8 any, E comparable](x func() (T1, T2, T3, T4, T5, T6, T7, T8, E)) (T1, T2, T3, T4, T5, T6, T7, T8) { var Nil E ret1, ret2, ret3, ret4, ret5, ret6, ret7, ret8, err := x() if err != Nil { panic(err) } return ret1, ret2, ret3, ret4, ret5, ret6, ret7, ret8 } func Unwrap9[T1, T2, T3, T4, T5, T6, T7, T8, T9 any, E comparable](x func() (T1, T2, T3, T4, T5, T6, T7, T8, T9, E)) (T1, T2, T3, T4, T5, T6, T7, T8, T9) { var Nil E ret1, ret2, ret3, ret4, ret5, ret6, ret7, ret8, ret9, err := x() if err != Nil { panic(err) } return ret1, ret2, ret3, ret4, ret5, ret6, ret7, ret8, ret9 } // there's no way of expressing a generic Unwrap without type parameter packs or some form // of macros... this will have to do for now... func main() { x := Unwrap1(func() (string, error) { return "foo", nil }) fmt.Println(x) }
Become a Patron
Sponsor on GitHub
Donate via PayPal
Source on GitHub
Mailing list
Installed libraries
Wiki
Report an issue
How it works
Contact the author
CE on Mastodon
CE on Bluesky
About the author
Statistics
Changelog
Version tree