tmp

package module
v0.0.0-...-55a3f40 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 23, 2025 License: MIT Imports: 5 Imported by: 1

README

go-tmp

Package tmp implements an expiring optional-type with a time-out, for the Go programming language.

In other programming languages, an optional-type might be known as: a option-type, or a maybe-type.

Documention

Online documentation, which includes examples, can be found at: http://godoc.org/codeberg.org/reiver/go-tmp

GoDoc

Example

Here is a simple example:

import "codeberg.org/reiver/go-tmp"

// ...

var until time.Time = time.Now().Add(8 * time.Hour)

var temporal tmp.Temporal[string] = tmp.Temporary(value, until)

// ...

// If the temporal has expired then this will return the optional value 'nothing'.
// Else, it will return the optional value 'something' (containing the same internal value that was inside of the temporal).
optional := temporal.Optional()

val, found := optional.Get()
if found {
	// ...
} else {
	// ...

}

Import

To import package tmp use import code like the follownig:

import "codeberg.org/reiver/go-tmp"

Installation

To install package tmp do the following:

GOPROXY=direct go get codeberg.org/reiver/go-tmp

Author

Package tmp was written by Charles Iliya Krempeaux

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Temporal

type Temporal[T any] struct {
	// contains filtered or unexported fields
}

func Nothing

func Nothing[T any]() Temporal[T]

func Permanent

func Permanent[T any](value T) Temporal[T]

func Temporary

func Temporary[T any](value T, until time.Time) Temporal[T]

func (Temporal[T]) Filter

func (receiver Temporal[T]) Filter(fn func(T) bool) Temporal[T]

func (Temporal[T]) Get

func (receiver Temporal[T]) Get() (T, bool)

func (Temporal[T]) GoString

func (receiver Temporal[T]) GoString() string

func (Temporal[T]) IsDefunct

func (receiver Temporal[T]) IsDefunct() bool

func (Temporal[T]) IsDefunctWhen

func (receiver Temporal[T]) IsDefunctWhen(when time.Time) bool

func (Temporal[T]) IsExtant

func (receiver Temporal[T]) IsExtant() bool

func (Temporal[T]) MarshalJSON

func (receiver Temporal[T]) MarshalJSON() ([]byte, error)

MarshalJSON makes it so json.Marshaler is implemented.

func (Temporal[T]) Optional

func (receiver Temporal[T]) Optional() opt.Optional[T]

Optional returns a optional-type (also called an option-type and maybe-type) based on the temporal-type. If the temporal-type or defunct, then it returns 'nothing'. Else it returns 'something'.

func (*Temporal[T]) UnmarshalJSON

func (receiver *Temporal[T]) UnmarshalJSON(data []byte) error

UnmarshalJSON makes it so json.Unmarshaler is implemented.

func (Temporal[T]) WhenDefunct

func (receiver Temporal[T]) WhenDefunct(fn func())

func (Temporal[T]) WhenExtant

func (receiver Temporal[T]) WhenExtant(fn func(T))

func (Temporal[T]) WhenNothing

func (receiver Temporal[T]) WhenNothing(fn func())

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL