Corrections diverses du package number + Ajout de stringers pour opition.Option et option.Choice
This commit is contained in:
parent
eff6ae9d7e
commit
ec6a3ba492
4 changed files with 52 additions and 14 deletions
|
|
@ -1,5 +1,9 @@
|
|||
package option
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// Option permet de définir des valeurs alternative.
|
||||
type Choice[T1 any, T2 any] struct {
|
||||
left Option[T1]
|
||||
|
|
@ -44,3 +48,16 @@ func (c Choice[T1, T2]) IsRight() bool {
|
|||
func (c Choice[T1, T2]) IsNil() bool {
|
||||
return !c.IsLeft() && !c.IsRight()
|
||||
}
|
||||
|
||||
func (c Choice[T1, T2]) String() string {
|
||||
return fmt.Sprintf(`{
|
||||
left: {
|
||||
value: %v,
|
||||
ok: %v,
|
||||
},
|
||||
right: {
|
||||
value: %v,
|
||||
ok: %v,
|
||||
},
|
||||
}`, c.left.v, c.left.ok, c.right.v, c.right.ok)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,9 @@
|
|||
package option
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// Option permet de définir des valeurs optionnelles, afin de se passer de nil.
|
||||
type Option[T any] struct {
|
||||
v T
|
||||
|
|
@ -29,3 +33,10 @@ func (o Option[T]) Get() (v T, ok bool) {
|
|||
func (o Option[T]) IsDefined() bool {
|
||||
return o.ok
|
||||
}
|
||||
|
||||
func (o Option[T]) String() string {
|
||||
return fmt.Sprintf(`{
|
||||
value: %v,
|
||||
ok: %v,
|
||||
}`, o.v, o.ok)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue