We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
Option.String
1 parent e1d9b1a commit 8a5bfadCopy full SHA for 8a5bfad
fn/option.go
@@ -1,12 +1,23 @@
1
package fn
2
3
-// Option[A] represents a value which may or may not be there. This is very
+import "fmt"
4
+
5
+// Option represents a value which may or may not be there. This is very
6
// often preferable to nil-able pointers.
7
type Option[A any] struct {
8
isSome bool
9
some A
10
}
11
12
+// String returns a string representation of the Option.
13
+func (o Option[A]) String() string {
14
+ if o.isSome {
15
+ return fmt.Sprintf("Some(%v)", o.some)
16
+ }
17
18
+ return "None"
19
+}
20
21
// Some trivially injects a value into an optional context.
22
//
23
// Some : A -> Option[A].
0 commit comments