Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var SD miscT
SD is the namespace for SD-like functions.
Functions ¶
func Embeds ¶
Embeds calls the Embeds method on the given element and returns the result.
Parameters:
- elem: The element to call the Embeds method on.
Returns:
- T: The result of the Embeds method.
- bool: True if the element has an Embeds method and false otherwise.
func Innermost ¶
func Innermost[T comparable](elem any) (T, bool)
Innermost retrieves the innermost embedded element of the given type from the provided element.
The function continuously calls the Embeds method to access nested elements until it encounters an element that either does not have an Embeds method or is equivalent to the zero value of the specified type.
Parameters:
- elem: The element from which to extract the innermost embedded element.
Returns:
- T: The innermost embedded element of type T.
- bool: True if such an element is found and convertible to type T, false otherwise.
func TowerOfEmbeds ¶
func TowerOfEmbeds[T comparable](elem any) ([]T, bool)
TowerOfEmbeds returns the tower of embeds of the given element where the first element is the innermost base of the element and the last one is the given element itself.
The tower stops at the first nil element.
Parameters:
- elem: The element.
Returns:
- []T: The tower of embeds.
- bool: True if the tower is not empty and the last element is of type T, false otherwise.
func Try ¶
func Try(fn func()) error
Try executes the provided function and recovers from any panic that occurs, returning it as an error.
Returns:
- error: An error if a panic occurred, or nil if no panic occurred.
func WithContext ¶
func WithContext[T comparable](elem any, key string, value any) (T, bool)
WithContext calls the WithContext method on the given element and returns the result.
Parameters:
- elem: The element to call the WithContext method on.
- key: The key to add to the context.
- value: The value to add to the context.
Returns:
- T: The result of the WithContext method. The type of this value must be T.
- bool: True if the element has a WithContext method and false otherwise.
Types ¶
This section is empty.