Files
zeekayandHanzo Dev ac0def4322 the corporate name is Lux Industries Inc
Lux Partners Limited is not the entity behind this work. Every place the
old name stood — copyright lines, site footers, brand config, legal and
compliance text — now names the company that actually holds it.

lux.fund is the exception and is not renamed to match: that site belongs
to Lux Assets Management LLC, a different company, and it says so.

Two kinds of line were left for a person rather than rewritten. A dated
news item recording that Lux Partners Limited was established in the Isle
of Man is a historical fact, and renaming it would falsify the record. And
a sentence asserting that the company is domiciled in the Isle of Man is a
claim about a jurisdiction, not a name — an Inc or an LLC is not an Isle
of Man company, so swapping the name there would assert something untrue.

Co-authored-by: Hanzo Dev <[email protected]>
2026-08-28 11:07:38 -07:00

73 lines
1.7 KiB
Go

// Copyright (C) 2025, Lux Industries Inc All rights reserved.
// See the file LICENSE for licensing terms.
package utils
import (
"context"
"os"
"os/signal"
"slices"
"time"
"github.com/luxfi/constants"
)
// Unique returns a new slice containing only the unique elements from the input slice.
func Unique[T comparable](arr []T) []T {
visited := map[T]bool{}
unique := []T{}
for _, e := range arr {
if !visited[e] {
unique = append(unique, e)
visited[e] = true
}
}
return unique
}
func Belongs[T comparable](input []T, elem T) bool {
return slices.Contains(input, elem)
}
func Map[T, U any](input []T, f func(T) U) []U {
output := make([]U, 0, len(input))
for _, e := range input {
output = append(output, f(e))
}
return output
}
func Uint32Sort(arr []uint32) {
slices.Sort(arr)
}
// GetAPIContext returns a context for API requests.
func GetAPIContext() (context.Context, context.CancelFunc) {
return GetTimedContext(constants.APIRequestTimeout)
}
// GetAPILargeContext returns a context for API requests with large timeout.
func GetAPILargeContext() (context.Context, context.CancelFunc) {
return GetTimedContext(constants.APIRequestLargeTimeout)
}
// GetTimedContext returns a context with the given timeout.
func GetTimedContext(timeout time.Duration) (context.Context, context.CancelFunc) {
parent, sigCancel := signal.NotifyContext(context.Background(), os.Interrupt)
ctx, timeCancel := context.WithTimeout(parent, timeout)
return ctx, func() {
sigCancel()
timeCancel()
}
}
// PointersSlice converts a slice of values to a slice of pointers
func PointersSlice[T any](values []T) []*T {
pointers := make([]*T, len(values))
for i := range values {
pointers[i] = &values[i]
}
return pointers
}