Table of Contents

Class ArrayExtensions

Namespace
Npp.DotNet.Plugin.Extensions
Assembly
Npp.DotNet.Plugin.dll
public static class ArrayExtensions
Inheritance
ArrayExtensions
Inherited Members

Methods

ArrayToString<T>(IList<T>)

e.g., int[]{1,2,3,4,5} -> "[1, 2, 3, 4, 5]"

public static string ArrayToString<T>(this IList<T> list)

Parameters

list IList<T>

Returns

string

Type Parameters

T

ClampWithinLen(int, int, bool)

If num is negative, use Python-style negative indices (e.g., -1 is the last element, -len is the first elememnt) Otherwise, restrict num to between 0 and len (inclusive unless is_start_idx)

public static int ClampWithinLen(int len, int num, bool is_start_idx)

Parameters

len int
num int
is_start_idx bool

Returns

int

FirstIfOutOfBounds<T>(IList<T>, int)

Return the first element of list if idx is not a valid index for this IList.
Otherwise return list[idx]

public static T FirstIfOutOfBounds<T>(this IList<T> list, int idx)

Parameters

list IList<T>
idx int

Returns

T

Type Parameters

T

LazySlice<T>(IList<T>, int?, int?, int?)

Allows the use of Python-style slices, where start, stop, and stride must be declared as individual paramters.
Thus e.g. arr.Slice(2, null, -1) is just like arr[slice(2, None, -1)] in Python.
This just yields the elements one by one.
If you want a function that yields a shallow copy of the sliced region of the iterable, use Slice<T> instead.

public static IEnumerable<T> LazySlice<T>(this IList<T> source, int? start, int? stop = null, int? stride = null)

Parameters

source IList<T>
start int?
stop int?
stride int?

Returns

IEnumerable<T>

Type Parameters

T

LazySlice<T>(IList<T>, int?[])

This just yields the elements one by one.
If you want a function that yields a shallow copy of the sliced region of the iterable, use Slice<T> instead.

public static IEnumerable<T> LazySlice<T>(this IList<T> source, int?[] slicer)

Parameters

source IList<T>
slicer int?[]

Returns

IEnumerable<T>

Type Parameters

T

LazySlice<T>(IList<T>, string)

Allows the use of Python-style slices, passed as strings (e.g., ":", "1::-2").
Because LazySlice is an extension method, all arrays in this namespace can use this method.
See https://stackoverflow.com/questions/509211/understanding-slicing This just yields the elements one by one.
If you want a function that yields a shallow copy of the sliced region of the iterable, use Slice<T> instead.

public static IEnumerable<T> LazySlice<T>(this IList<T> source, string slicer)

Parameters

source IList<T>
slicer string

Returns

IEnumerable<T>

Type Parameters

T

Pop<T>(List<T>)

Removes and returns the last element of a list.

public static T Pop<T>(this List<T> list)

Parameters

list List<T>

Returns

T

Type Parameters

T

Shuffle<T>(IList<T>)

randomize the order of the elements in arr

public static void Shuffle<T>(this IList<T> arr)

Parameters

arr IList<T>

Type Parameters

T

Slice(string, int, int, int)

public static string Slice(this string source, int start, int stop, int stride)

Parameters

source string
start int
stop int
stride int

Returns

string

Slice(string, int?[])

s_slice(x: string, sli: integer | slicer) -> string
uses Python slicing syntax.
EXAMPLES:

  • s_slice(abcde, 1:-2) returns "bc"
  • s_slice(abcde, :2) returns "ab"
  • s_slice(abcde, -2) returns "d"
public static string Slice(this string source, int?[] slicer)

Parameters

source string
slicer int?[]

Returns

string

Slice(string, string)

public static string Slice(this string source, string slicer)

Parameters

source string
slicer string

Returns

string

Slice<T>(IList<T>, int?, int?, int?)

Allows use of Python-style slices, except that these create a copy of the sliced object rather than a view.
For higher performance at the cost of only producing an iterator and not a new iterable, use LazySlice.
See the documentation for LazySlice with three int arguments.

public static IList<T> Slice<T>(this IList<T> source, int? start, int? stop = null, int? stride = null)

Parameters

source IList<T>
start int?
stop int?
stride int?

Returns

IList<T>

Type Parameters

T

Exceptions

NotImplementedException

Slice<T>(IList<T>, int?[])

Allows use of Python-style slices, except that these create a copy of the sliced object rather than a view.
For higher performance at the cost of only producing an iterator and not a new iterable, use LazySlice.
See the documentation for LazySlice with three int arguments.

public static IList<T> Slice<T>(this IList<T> source, int?[] slicer)

Parameters

source IList<T>
slicer int?[]

Returns

IList<T>

Type Parameters

T

Exceptions

NotImplementedException

Slice<T>(IList<T>, string)

Allows use of Python-style slices, except that these create a copy of the sliced object rather than a view.
For higher performance at the cost of only producing an iterator and not a new iterable, use LazySlice.
See the documentation for LazySlice with a string argument

public static IList<T> Slice<T>(this IList<T> source, string slicer)

Parameters

source IList<T>
slicer string

Returns

IList<T>

Type Parameters

T

Exceptions

NotImplementedException

WrappedIndex(string, int, out string)

see WrappedIndex docs for lists and arrays.
Returns null if idx is out of bounds.
EXAMPLES

  1. WrappedIndex("abc", 1) -> "b"
  2. WrappedIndex("abc", -3) -> "a"
  3. WrappedIndex("abc", 4) -> null
  4. WrappedIndex("abc", -5) -> null
public static bool WrappedIndex(this string source, int idx, out string atIdx)

Parameters

source string
idx int
atIdx string

Returns

bool

WrappedIndex<T>(IList<T>, int, out T)

If idx is between [0, source length) exclusive, atIdx = source[idx] and return true.
If idx is between [-(source length), -1] inclusive, atIdx = source[idx + source length] and return true.
else atIdx = default(T) and return false

public static bool WrappedIndex<T>(this IList<T> source, int idx, out T atIdx)

Parameters

source IList<T>
idx int
atIdx T

Returns

bool

Type Parameters

T