Files
zeekay 7cf87b230b node-unified is the node
The module already called itself github.com/luxfi/node while containing no node
in Go: cmd/luxd was twenty-one lines that printed the size of a few types, and
the Go column of the matrix measured a VM plugin. A repo that fetches the thing
it claims to be has not replaced it, so the Go sources move in — 1515 files,
the daemon and everything under it — and the build reaches outside this module
for nothing.

Rust and C++ sit beside it unchanged and are still measured against it by the
differential. That is the point of one repo: the reference implementation and
the two ports are the same checkout, so parity is a thing you can run rather
than a thing you assert.

Verified: builds, and the closure carries no lux-private — checked at build time
rather than believed. The daemon starts twelve chains on a local network
(P X C Q Z A B G K M F, plus D through its plugin) and reports healthy.
2026-09-07 16:15:25 -07:00

77 lines
1.9 KiB
Go

// Copyright (C) 2019-2025, Lux Industries Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package maybe
import "fmt"
// Maybe T = Some T | Nothing.
// A data wrapper that allows values to be something [Some T] or nothing [Nothing].
// Invariant: If [hasValue] is false, then [value] is the zero value of type T.
// Maybe is used to wrap types:
// * That can't be represented by nil.
// * That use nil as a valid value instead of an indicator of a missing value.
// For more info see https://en.wikipedia.org/wiki/Option_type
type Maybe[T any] struct {
hasValue bool
// If [hasValue] is false, [value] is the zero value of type T.
value T
}
// Some returns a new Maybe[T] with the value val.
// If m.IsNothing(), returns the zero value of type T.
func Some[T any](val T) Maybe[T] {
return Maybe[T]{
value: val,
hasValue: true,
}
}
// Nothing returns a new Maybe[T] with no value.
func Nothing[T any]() Maybe[T] {
return Maybe[T]{}
}
// IsNothing returns false iff [m] has a value.
func (m Maybe[T]) IsNothing() bool {
return !m.hasValue
}
// HasValue returns true iff [m] has a value.
func (m Maybe[T]) HasValue() bool {
return m.hasValue
}
// Value returns the value of [m].
func (m Maybe[T]) Value() T {
return m.value
}
func (m Maybe[T]) String() string {
if !m.hasValue {
return fmt.Sprintf("Nothing[%T]", m.value)
}
return fmt.Sprintf("Some[%T]{%v}", m.value, m.value)
}
// Bind returns Nothing iff [m] is Nothing.
// Otherwise applies [f] to the value of [m] and returns the result as a Some.
func Bind[T, U any](m Maybe[T], f func(T) U) Maybe[U] {
if m.IsNothing() {
return Nothing[U]()
}
return Some(f(m.Value()))
}
// Equal returns true if both m1 and m2 are nothing or have the same value according to [equalFunc].
func Equal[T any](m1 Maybe[T], m2 Maybe[T], equalFunc func(T, T) bool) bool {
if m1.IsNothing() {
return m2.IsNothing()
}
if m2.IsNothing() {
return false
}
return equalFunc(m1.Value(), m2.Value())
}