Исходники и презентации

This commit is contained in:
2025-05-23 07:26:39 +03:00
parent aa948179d5
commit 02d8430a3a
514 changed files with 13773 additions and 0 deletions

View File

@ -0,0 +1,42 @@
package main
import "fmt"
var NullOptional = Optional[int]{}
type Optional[T any] struct {
value T
present bool
}
func NewOptional[T any](value T) Optional[T] {
return Optional[T]{
value: value,
present: true,
}
}
func (o *Optional[T]) HasValue() bool {
return o.present
}
func (o *Optional[T]) Value() T {
return o.value
}
func divide(lhs, rhs int) Optional[int] {
if rhs == 0 {
return NullOptional
}
result := lhs / rhs
return NewOptional(result)
}
func main() {
x := 100
y := 0
optional := divide(x, y)
fmt.Println(optional)
}