Show / Hide Table of Contents

Class OptionCollectionExtensions

Extension methods for using collections with Option<T>.

Inheritance
object
OptionCollectionExtensions
Inherited Members
object.Equals(object)
object.Equals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
object.ReferenceEquals(object, object)
object.ToString()
Namespace: RustyOptions
Assembly: RustyOptions.dll
Syntax
public static class OptionCollectionExtensions

Methods

| Edit this page View Source

DequeueOrNone<T>(ConcurrentQueue<T>)

Returns an Option<T> that contains the object at the beginning of the PriorityQueue if one is present. The object is removed from the PriorityQueue.

Declaration
public static Option<T> DequeueOrNone<T>(this ConcurrentQueue<T> self) where T : notnull
Parameters
Type Name Description
ConcurrentQueue<T> self

The queue.

Returns
Type Description
Option<T>

An Option<T> that is Some if the queue has any values, and None if the queue is empty.

Type Parameters
Name Description
T

The type contained by the queue and the returned option.

| Edit this page View Source

DequeueOrNone<T>(Queue<T>)

Returns an Option<T> that contains the object at the beginning of the Queue if one is present. The object is removed from the Queue.

Declaration
public static Option<T> DequeueOrNone<T>(this Queue<T> self) where T : notnull
Parameters
Type Name Description
Queue<T> self

The queue.

Returns
Type Description
Option<T>

An Option<T> that is Some if the queue has any values, and None if the queue is empty.

Type Parameters
Name Description
T

The type contained by the queue and the returned option.

| Edit this page View Source

DequeueOrNone<T>(ImmutableQueue<T>, out Option<T>)

Returns an Option<T> that contains the object at the beginning of the ImmutableQueue if one is present. The object is removed from the ImmutableQueue.

Declaration
public static ImmutableQueue<T> DequeueOrNone<T>(this ImmutableQueue<T> self, out Option<T> result) where T : notnull
Parameters
Type Name Description
ImmutableQueue<T> self

The queue.

Option<T> result

An Option<T> containing the value removed from the stack, if any.

Returns
Type Description
ImmutableQueue<T>

A modified verison of the ImmutableStack without the removed value.

Type Parameters
Name Description
T

The type contained by the queue and the returned option.

| Edit this page View Source

DequeueOrNone<T, TPriority>(PriorityQueue<T, TPriority>)

Returns an Option<T> that contains the object at the beginning of the PriorityQueue if one is present. The object is removed from the PriorityQueue.

Declaration
public static Option<(T Element, TPriority Priority)> DequeueOrNone<T, TPriority>(this PriorityQueue<T, TPriority> self) where T : notnull
Parameters
Type Name Description
PriorityQueue<T, TPriority> self

The queue.

Returns
Type Description
Option<(T Element, TPriority Priority)>

An Option<T> that is Some if the queue has any values, and None if the queue is empty.

Type Parameters
Name Description
T

The type contained by the queue and the returned option.

TPriority

The type of the priority value.

| Edit this page View Source

ElementAtOrNone<T>(IEnumerable<T>, int)

Returns an element at a specified position in a sequence if such exists.

Declaration
public static Option<T> ElementAtOrNone<T>(this IEnumerable<T> self, int index) where T : notnull
Parameters
Type Name Description
IEnumerable<T> self

The sequence to return the element from.

int index

The index in the sequence.

Returns
Type Description
Option<T>

An Option<T> instance containing the element if found.

Type Parameters
Name Description
T
Exceptions
Type Condition
ArgumentNullException

Thrown when self is null.

| Edit this page View Source

FirstOrNone<T>(IEnumerable<T>)

Returns the first element of a sequence if such exists.

Declaration
public static Option<T> FirstOrNone<T>(this IEnumerable<T> self) where T : notnull
Parameters
Type Name Description
IEnumerable<T> self

The sequence to return the first element from.

Returns
Type Description
Option<T>

An Option<T> instance containing the first element if present.

Type Parameters
Name Description
T
Exceptions
Type Condition
ArgumentNullException

Thrown when self is null.

| Edit this page View Source

FirstOrNone<T>(IEnumerable<T>, Func<T, bool>)

Returns the first element of a sequence, satisfying a specified predicate, if such exists.

Declaration
public static Option<T> FirstOrNone<T>(this IEnumerable<T> self, Func<T, bool> predicate) where T : notnull
Parameters
Type Name Description
IEnumerable<T> self

The sequence to return the first element from.

Func<T, bool> predicate

The predicate to filter by.

Returns
Type Description
Option<T>

An Option<T> instance containing the first matching element, if present.

Type Parameters
Name Description
T
Exceptions
Type Condition
ArgumentNullException

Thrown when self or predicate is null.

| Edit this page View Source

GetValueOrNone<T>(HashSet<T>, T)

Searches the set for a given value and returns the equal value it finds, if any.

Declaration
public static Option<T> GetValueOrNone<T>(this HashSet<T> self, T equalValue) where T : notnull
Parameters
Type Name Description
HashSet<T> self

The HashSet.

T equalValue

The value to search for.

Returns
Type Description
Option<T>

Some containing the value the search found, or None.

Type Parameters
Name Description
T

The type of the value.

| Edit this page View Source

GetValueOrNone<T>(SortedSet<T>, T)

Searches the set for a given value and returns the equal value it finds, if any.

Declaration
public static Option<T> GetValueOrNone<T>(this SortedSet<T> self, T equalValue) where T : notnull
Parameters
Type Name Description
SortedSet<T> self

The SortedSet.

T equalValue

The value to search for.

Returns
Type Description
Option<T>

Some containing the value the search found, or None.

Type Parameters
Name Description
T

The type of the value.

| Edit this page View Source

GetValueOrNone<T>(ImmutableHashSet<T>, T)

Searches the set for a given value and returns the equal value it finds, if any.

Declaration
public static Option<T> GetValueOrNone<T>(this ImmutableHashSet<T> self, T equalValue) where T : notnull
Parameters
Type Name Description
ImmutableHashSet<T> self

The HashSet.

T equalValue

The value to search for.

Returns
Type Description
Option<T>

Some containing the value the search found, or None.

Type Parameters
Name Description
T

The type of the value.

| Edit this page View Source

GetValueOrNone<T>(ImmutableSortedSet<T>, T)

Searches the set for a given value and returns the equal value it finds, if any.

Declaration
public static Option<T> GetValueOrNone<T>(this ImmutableSortedSet<T> self, T equalValue) where T : notnull
Parameters
Type Name Description
ImmutableSortedSet<T> self

The SortedSet.

T equalValue

The value to search for.

Returns
Type Description
Option<T>

Some containing the value the search found, or None.

Type Parameters
Name Description
T

The type of the value.

| Edit this page View Source

GetValueOrNone<TKey, TValue>(IEnumerable<KeyValuePair<TKey, TValue>>, TKey)

Gets the value associated with the given key from the dictionary as an Option<T>.

Declaration
public static Option<TValue> GetValueOrNone<TKey, TValue>(this IEnumerable<KeyValuePair<TKey, TValue>> self, TKey key) where TKey : notnull where TValue : notnull
Parameters
Type Name Description
IEnumerable<KeyValuePair<TKey, TValue>> self

The dictionary.

TKey key

The key.

Returns
Type Description
Option<TValue>

If the key is found, returns Some(value). Otherwise, None.

Type Parameters
Name Description
TKey

The type of the key.

TValue

The type of the value.

Exceptions
Type Condition
ArgumentNullException

Thrown when self is null.

| Edit this page View Source

LastOrNone<T>(IEnumerable<T>)

Returns the last element of a sequence if such exists.

Declaration
public static Option<T> LastOrNone<T>(this IEnumerable<T> self) where T : notnull
Parameters
Type Name Description
IEnumerable<T> self

The sequence to return the last element from.

Returns
Type Description
Option<T>

An Option<T> instance containing the last element if present.

Type Parameters
Name Description
T
Exceptions
Type Condition
ArgumentNullException

Thrown when self is null.

| Edit this page View Source

LastOrNone<T>(IEnumerable<T>, Func<T, bool>)

Returns the last element of a sequence, satisfying a specified predicate, if such exists.

Declaration
public static Option<T> LastOrNone<T>(this IEnumerable<T> self, Func<T, bool> predicate) where T : notnull
Parameters
Type Name Description
IEnumerable<T> self

The sequence to return the last element from.

Func<T, bool> predicate

The predicate to filter by.

Returns
Type Description
Option<T>

An Option<T> instance containing the last element if present.

Type Parameters
Name Description
T
Exceptions
Type Condition
ArgumentNullException

Thrown when self or predicate is null.

| Edit this page View Source

PeekOrNone<T>(ConcurrentBag<T>)

Attempts to return an object from the ConcurrentBag<T> without removing it.

Declaration
public static Option<T> PeekOrNone<T>(this ConcurrentBag<T> self) where T : notnull
Parameters
Type Name Description
ConcurrentBag<T> self

The collection.

Returns
Type Description
Option<T>

Returns a Some containing the value if there is a value, otherwise None.

Type Parameters
Name Description
T

The item type.

| Edit this page View Source

PeekOrNone<T>(ConcurrentQueue<T>)

Attempts to return an object from the beginning of the ConcurrentQueue<T> without removing it.

Declaration
public static Option<T> PeekOrNone<T>(this ConcurrentQueue<T> self) where T : notnull
Parameters
Type Name Description
ConcurrentQueue<T> self

The collection.

Returns
Type Description
Option<T>

Returns a Some containing the value if there is a value, otherwise None.

Type Parameters
Name Description
T

The item type.

| Edit this page View Source

PeekOrNone<T>(ConcurrentStack<T>)

Attempts to return an object from the top of the ConcurrentStack<T> without removing it.

Declaration
public static Option<T> PeekOrNone<T>(this ConcurrentStack<T> self) where T : notnull
Parameters
Type Name Description
ConcurrentStack<T> self

The collection.

Returns
Type Description
Option<T>

Returns a Some containing the value if there is a value, otherwise None.

Type Parameters
Name Description
T

The item type.

| Edit this page View Source

PeekOrNone<T>(Queue<T>)

Returns an Option<T> that contains the object at the beginning of the Queue if one is present. The object is not removed from the Queue.

Declaration
public static Option<T> PeekOrNone<T>(this Queue<T> self) where T : notnull
Parameters
Type Name Description
Queue<T> self

The queue.

Returns
Type Description
Option<T>

An Option<T> that is Some if the queue has any values, and None if the queue is empty.

Type Parameters
Name Description
T

The type contained by the queue and the returned option.

| Edit this page View Source

PeekOrNone<T>(Stack<T>)

Returns an Option<T> that contains the object at the top of the Stack if one is present. The object is not removed from the Stack.

Declaration
public static Option<T> PeekOrNone<T>(this Stack<T> self) where T : notnull
Parameters
Type Name Description
Stack<T> self

The stack.

Returns
Type Description
Option<T>

An Option<T> that is Some if the stack has any values, and None if the stack is empty.

Type Parameters
Name Description
T

The type contained by the stack and the returned option.

| Edit this page View Source

PeekOrNone<T>(ImmutableQueue<T>)

Returns an Option<T> that contains the object at the beginning of the ImmutableQueue if one is present. The object is not removed from the ImmutableQueue.

Declaration
public static Option<T> PeekOrNone<T>(this ImmutableQueue<T> self) where T : notnull
Parameters
Type Name Description
ImmutableQueue<T> self

The queue.

Returns
Type Description
Option<T>

An Option<T> that is Some if the queue has any values, and None if the queue is empty.

Type Parameters
Name Description
T

The type contained by the queue and the returned option.

| Edit this page View Source

PeekOrNone<T>(ImmutableStack<T>)

Returns an Option<T> that contains the object at the top of the ImmutableStack if one is present. The object is not removed from the ImmutableStack.

Declaration
public static Option<T> PeekOrNone<T>(this ImmutableStack<T> self) where T : notnull
Parameters
Type Name Description
ImmutableStack<T> self

The stack.

Returns
Type Description
Option<T>

An Option<T> that is Some if the stack has any values, and None if the stack is empty.

Type Parameters
Name Description
T

The type contained by the stack and the returned option.

| Edit this page View Source

PeekOrNone<T, TPriority>(PriorityQueue<T, TPriority>)

Returns an Option<T> that contains the object at the beginning of the PriorityQueue if one is present. The object is not removed from the PriorityQueue.

Declaration
public static Option<(T Element, TPriority Priority)> PeekOrNone<T, TPriority>(this PriorityQueue<T, TPriority> self) where T : notnull
Parameters
Type Name Description
PriorityQueue<T, TPriority> self

The queue.

Returns
Type Description
Option<(T Element, TPriority Priority)>

An Option<T> that is Some if the queue has any values, and None if the queue is empty.

Type Parameters
Name Description
T

The type contained by the queue and the returned option.

TPriority

The type of the priority value.

| Edit this page View Source

PopOrNone<T>(ConcurrentStack<T>)

Returns an Option<T> that contains the object at the top of the Stack if one is present. The object is removed from the Stack.

Declaration
public static Option<T> PopOrNone<T>(this ConcurrentStack<T> self) where T : notnull
Parameters
Type Name Description
ConcurrentStack<T> self

The stack.

Returns
Type Description
Option<T>

An Option<T> that is Some if the stack has any values, and None if the stack is empty.

Type Parameters
Name Description
T

The type contained by the stack and the returned option.

| Edit this page View Source

PopOrNone<T>(Stack<T>)

Returns an Option<T> that contains the object at the top of the Stack if one is present. The object is removed from the Stack.

Declaration
public static Option<T> PopOrNone<T>(this Stack<T> self) where T : notnull
Parameters
Type Name Description
Stack<T> self

The stack.

Returns
Type Description
Option<T>

An Option<T> that is Some if the stack has any values, and None if the stack is empty.

Type Parameters
Name Description
T

The type contained by the stack and the returned option.

| Edit this page View Source

PopOrNone<T>(ImmutableStack<T>, out Option<T>)

Sets result to an Option<T> that contains the object at the top of the ImmutableStack if one is present. A modified version of the stack without that value is returned.

Declaration
public static ImmutableStack<T> PopOrNone<T>(this ImmutableStack<T> self, out Option<T> result) where T : notnull
Parameters
Type Name Description
ImmutableStack<T> self

The stack.

Option<T> result

An Option<T> containing the value removed from the stack, if any.

Returns
Type Description
ImmutableStack<T>

A modified verison of the ImmutableStack without the removed value.

Type Parameters
Name Description
T

The type contained by the stack and the returned option.

| Edit this page View Source

SelectWhere<T1, T2>(IEnumerable<T1>, Func<T1, Option<T2>>)

Applies a function to each element of a sequence and returns a sequence of the values inside any Some results. Can be used to transform and filter in a single operation, similar to applying Select/Where/Select, but with better performance.

Declaration
public static IEnumerable<T2> SelectWhere<T1, T2>(this IEnumerable<T1> self, Func<T1, Option<T2>> selector) where T1 : notnull where T2 : notnull
Parameters
Type Name Description
IEnumerable<T1> self

The incoming sequence.

Func<T1, Option<T2>> selector

A function that takes a value from the in coming sequence, and returns an Option<T> that will have any value included in the resulting sequence.

Returns
Type Description
IEnumerable<T2>

A sequence containing the values for which the selector function returns Some.

Type Parameters
Name Description
T1

The type contained in the incoming sequence.

T2

The type contained in the resulting sequence.

Exceptions
Type Condition
ArgumentNullException

Thrown if self or selector is null.

| Edit this page View Source

SingleOrNone<T>(IEnumerable<T>)

Returns a single element from a sequence, if it exists and is the only element in the sequence.

Declaration
public static Option<T> SingleOrNone<T>(this IEnumerable<T> self) where T : notnull
Parameters
Type Name Description
IEnumerable<T> self

The sequence to return the element from.

Returns
Type Description
Option<T>

An Option<T> instance containing the element if present.

Type Parameters
Name Description
T
Exceptions
Type Condition
ArgumentNullException

Thrown when self is null.

| Edit this page View Source

SingleOrNone<T>(IEnumerable<T>, Func<T, bool>)

Returns a single element from a sequence, satisfying a specified predicate, if it exists and is the only element in the sequence.

Declaration
public static Option<T> SingleOrNone<T>(this IEnumerable<T> self, Func<T, bool> predicate) where T : notnull
Parameters
Type Name Description
IEnumerable<T> self

The sequence to return the element from.

Func<T, bool> predicate

The predicate to filter by.

Returns
Type Description
Option<T>

An Option<T> instance containing the element if present.

Type Parameters
Name Description
T
Exceptions
Type Condition
ArgumentNullException

Thrown when self or predicate is null.

| Edit this page View Source

TakeOrNone<T>(IProducerConsumerCollection<T>)

Attempts to remove and return an object from the collection.

Declaration
public static Option<T> TakeOrNone<T>(this IProducerConsumerCollection<T> self) where T : notnull
Parameters
Type Name Description
IProducerConsumerCollection<T> self

The collection.

Returns
Type Description
Option<T>

Returns a Some containing the value if there is a value, otherwise None.

Type Parameters
Name Description
T

The item type.

| Edit this page View Source

Values<T>(IEnumerable<Option<T>>)

Flattens a sequence of Option<T> into a sequence containing all inner values. Empty elements are discarded.

Declaration
public static IEnumerable<T> Values<T>(this IEnumerable<Option<T>> self) where T : notnull
Parameters
Type Name Description
IEnumerable<Option<T>> self

The sequence of options.

Returns
Type Description
IEnumerable<T>

A flattened sequence of values.

Type Parameters
Name Description
T
Exceptions
Type Condition
ArgumentNullException

Thrown when self is null.

  • Edit this page
  • View Source
In this article
Back to top Generated by DocFX