Ferrous API Reference

All Types / Ferrous.Results

class SafeCollectionExtensions

public static class SafeCollectionExtensions

Rust-inspired bounds-safe .Get(...) indexing extensions returning Option<T> instead of throwing IndexOutOfRangeException or KeyNotFoundException.

Methods

public static Option<T> Get<T>(this T[] array, int index)

Returns the element at index as Option<T>.Some, or Option<T>.None if out of bounds.

public static Option<T> Get<T>(this ReadOnlySpan<T> span, int index)

Returns the element at index as Option<T>.Some, or Option<T>.None if out of bounds.

public static Option<T> Get<T>(this Span<T> span, int index)

Returns the element at index as Option<T>.Some, or Option<T>.None if out of bounds.

public static Option<T> Get<T>(this List<T> list, int index)

Returns the element at index as Option<T>.Some, or Option<T>.None if out of bounds.

public static Option<T> Get<T>(this IReadOnlyList<T> list, int index)

Returns the element at index as Option<T>.Some, or Option<T>.None if out of bounds.

public static Option<TValue> Get<TKey, TValue>(this IReadOnlyDictionary<TKey, TValue> dictionary, TKey key) where TKey : notnull

Returns the value for key as Option<T>.Some, or Option<T>.None if not found.

public static Option<TValue> Get<TKey, TValue>(this Dictionary<TKey, TValue> dictionary, TKey key) where TKey : notnull

Returns the value for key as Option<T>.Some, or Option<T>.None if not found.