Skip to content

Commit f63ee7e

Browse files
authored
feat(go): adding helper methods for result and option (#1463)
Signed-off-by: Andrew Steurer <94206073+asteurer@users.noreply.github.com>
1 parent c416d23 commit f63ee7e

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

crates/go/src/wit_option.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ func (self Option[T]) SomeOr(value T) T {
2929
}
3030
}
3131

32+
func (self Option[T]) IsSome() bool {
33+
return self.tag == OptionSome
34+
}
35+
36+
func (self Option[T]) IsNone() bool {
37+
return self.tag == OptionNone
38+
}
39+
3240
func None[T any]() Option[T] {
3341
return Option[T]{OptionNone, make([]T, 1)[0]}
3442
}

crates/go/src/wit_result.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ func (self Result[T, U]) Err() U {
2828
return self.value.(U)
2929
}
3030

31+
func (self Result[T, U]) IsErr() bool {
32+
return self.tag == ResultErr
33+
}
34+
35+
func (self Result[T, U]) IsOk() bool {
36+
return self.tag == ResultOk
37+
}
38+
3139
func Ok[T any, U any](value T) Result[T, U] {
3240
return Result[T, U]{ResultOk, value}
3341
}

0 commit comments

Comments
 (0)