PeanutButter
Loading...
Searching...
No Matches
PeanutButter.Utils.ListExtensions Class Reference

Provides methods on lists as one might expect from JavaScript. More...

Static Public Member Functions

static T Shift< T > (this IList< T > list)
 Removes the first item from the list and returns it.
static T Pop< T > (this IList< T > list)
 Removes the last item from the list and returns it.
static bool TryPop< T > (this IList< T > list, out T result)
 Attempt to pop the last element off of a list.
static bool TryShift< T > (this IList< T > list, out T result)
 Attempt to shift the first element off of a list.
static void Unshift< T > (this IList< T > list, T value)
 Inserts an item at the beginning of the list.
static void Push< T > (this IList< T > list, T value)
 Alias for .Add: appends an item to the list.
static IList< T > AddIf< T > (this IList< T > list, bool shouldAdd, T value)
 Adds the value to the list if the flag was set to true shortcut for: if (flag) { list.Add(value); }.
static IList< T > AddAll< T > (this IList< T > list, params T[] items)
 Adds all the provided items and returns the list.
static bool TryEjectFirst< T > (this IList< T > list, Func< T, bool > matcher, out T result)
 Attempts to eject the first matching.
static T EjectFirst< T > (this IList< T > list, Func< T, bool > matcher)
 Ejects the first matched item from the collection or throws if it cannot:
static bool TryEjectLast< T > (this IList< T > list, Func< T, bool > matcher, out T result)
 Tries to eject the first matched item from the collection.
static T EjectLast< T > (this IList< T > list, Func< T, bool > matcher)
 Ejects the first matched item from the collection or throws if it cannot:
static IList< T > Reversed< T > (this IList< T > list)
 Returns a NEW list: a copy of the provided on but with the order reversed.
static List< T > ReversedInPlace< T > (this List< T > list)
 Reverses the list IN-PLACE (modifies the original list) and returns it for fluent syntax.
static T[] ReversedInPlace< T > (this T[] array)
 Reverses the array IN-PLACE (modifies the original list) and returns it for fluent syntax.

Detailed Description

Provides methods on lists as one might expect from JavaScript.

Member Function Documentation

◆ AddAll< T >()

IList< T > PeanutButter.Utils.ListExtensions.AddAll< T > ( this IList< T > list,
params T[] items )
static

Adds all the provided items and returns the list.

Parameters
list
items
Template Parameters
T
Returns

◆ AddIf< T >()

IList< T > PeanutButter.Utils.ListExtensions.AddIf< T > ( this IList< T > list,
bool shouldAdd,
T value )
static

Adds the value to the list if the flag was set to true shortcut for: if (flag) { list.Add(value); }.

Parameters
list
shouldAdd
value
Template Parameters
T

◆ EjectFirst< T >()

T PeanutButter.Utils.ListExtensions.EjectFirst< T > ( this IList< T > list,
Func< T, bool > matcher )
static

Ejects the first matched item from the collection or throws if it cannot:

  • when no items to search, will throw InvalidOperationException
  • when not found, will throw NotFoundException
Parameters
list
matcher
Template Parameters
T
Returns
Exceptions
InvalidOperationException

◆ EjectLast< T >()

T PeanutButter.Utils.ListExtensions.EjectLast< T > ( this IList< T > list,
Func< T, bool > matcher )
static

Ejects the first matched item from the collection or throws if it cannot:

  • when no items to search, will throw InvalidOperationException
  • when not found, will throw NotFoundException
Parameters
list
matcher
Template Parameters
T
Returns
Exceptions
InvalidOperationException

◆ Pop< T >()

T PeanutButter.Utils.ListExtensions.Pop< T > ( this IList< T > list)
static

Removes the last item from the list and returns it.

Parameters
list
Template Parameters
T
Exceptions
InvalidOperationExceptionThrown when the list is empty
Returns

◆ Push< T >()

void PeanutButter.Utils.ListExtensions.Push< T > ( this IList< T > list,
T value )
static

Alias for .Add: appends an item to the list.

Parameters
list
value
Template Parameters
T

◆ Reversed< T >()

IList< T > PeanutButter.Utils.ListExtensions.Reversed< T > ( this IList< T > list)
static

Returns a NEW list: a copy of the provided on but with the order reversed.

Parameters
list
Template Parameters
T
Returns

◆ ReversedInPlace< T >() [1/2]

List< T > PeanutButter.Utils.ListExtensions.ReversedInPlace< T > ( this List< T > list)
static

Reverses the list IN-PLACE (modifies the original list) and returns it for fluent syntax.

Parameters
list
Template Parameters
T
Returns

◆ ReversedInPlace< T >() [2/2]

T[] PeanutButter.Utils.ListExtensions.ReversedInPlace< T > ( this T[] array)
static

Reverses the array IN-PLACE (modifies the original list) and returns it for fluent syntax.

Parameters
array
Template Parameters
T
Returns

◆ Shift< T >()

T PeanutButter.Utils.ListExtensions.Shift< T > ( this IList< T > list)
static

Removes the first item from the list and returns it.

Parameters
list
Template Parameters
T
Exceptions
InvalidOperationExceptionThrown when the list is empty
Returns

◆ TryEjectFirst< T >()

bool PeanutButter.Utils.ListExtensions.TryEjectFirst< T > ( this IList< T > list,
Func< T, bool > matcher,
out T result )
static

Attempts to eject the first matching.

Parameters
list
matcher
result
Template Parameters
T
Returns

◆ TryEjectLast< T >()

bool PeanutButter.Utils.ListExtensions.TryEjectLast< T > ( this IList< T > list,
Func< T, bool > matcher,
out T result )
static

Tries to eject the first matched item from the collection.

Parameters
list
matcher
result
Template Parameters
T
Returns
Exceptions
InvalidOperationException

◆ TryPop< T >()

bool PeanutButter.Utils.ListExtensions.TryPop< T > ( this IList< T > list,
out T result )
static

Attempt to pop the last element off of a list.

  • Returns true and sets the result when the list has elements
  • Returns false if the list has no elements to pop
Parameters
list
result
Template Parameters
T
Returns

◆ TryShift< T >()

bool PeanutButter.Utils.ListExtensions.TryShift< T > ( this IList< T > list,
out T result )
static

Attempt to shift the first element off of a list.

  • Returns true and sets the result when the list has elements
  • Returns false if the list has no elements to shift
Parameters
list
result
Template Parameters
T
Returns

◆ Unshift< T >()

void PeanutButter.Utils.ListExtensions.Unshift< T > ( this IList< T > list,
T value )
static

Inserts an item at the beginning of the list.

Parameters
list
value
Template Parameters
T

The documentation for this class was generated from the following file:
  • source/Utils/PeanutButter.Utils/ListExtensions.cs