ae.utils.array

Array utility functions

Members

Functions

contains
bool contains(in T[] arr, auto ref in V val)

Whether array contains value, no BS.

containsAt
bool containsAt(in T[] haystack, in T[] needle, size_t offset)

Like startsWith, but with an offset.

eat
bool eat(ref T[] arr, T[] prefix)

If arr starts with prefix, slice it off and return true. Otherwise leave arr unchaned and return false.

emptySlice
auto emptySlice()

Returns an empty, but non-null slice of T.

fromBytes
inout(T) fromBytes(inout(ubyte)[] bytes)
inout(T) fromBytes(inout(ubyte)[] bytes)

Reverse of bytes()

get
T get(T[] arr, size_t index)

Like AA.get - soft indexing, throws an Exception (not an Error) on out-of-bounds, even in release builds.

get
auto get(T[] arr, size_t index, auto ref T defaultValue)

Like AA.get - soft indexing, returns default value on out-of-bounds.

getExpand
T getExpand(ref T[] arr, size_t index)

Expand the array if index is out-of-bounds.

indexOf
sizediff_t indexOf(in T[] arr, in D val)

Complement to std.string.indexOf which works with arrays of non-character types. Unlike std.algorithm.countUntil, it does not auto-decode, and returns an index usable for array indexing/slicing.

indexOfElement
sizediff_t indexOfElement(in T[] arr, auto ref in D val)

Index of element, no BS.

list
auto list(auto ref Args args)

Equivalent of PHP's list language construct: http://php.net/manual/en/function.list.php

Works with arrays and tuples. Specify null as an argument to ignore that index (equivalent of list(x, , y) in PHP).

memmove
void memmove(T[] dst, in T[] src)

Like std.algorithm.copy, but without the auto-decode bullshit. https://issues.dlang.org/show_bug.cgi?id=13650

pluck
T pluck(ref T[] arr)

Select and return a random element from the array, and remove it from the array.

putExpand
T putExpand(ref T[] arr, size_t index, auto ref T value)

Expand the array if index is out-of-bounds.

sample
auto ref sample(T[] arr)

Select and return a random element from the array.

skipUntil
T[] skipUntil(ref T[] source, D delim, bool orUntilEnd = false)

Returns the slice of source up to the first occurrence of delim, and fast-forwards source to the point after delim. If delim is not found, the behavior depends on orUntilEnd: - If orUntilEnd is false (default), it returns null and leaves source unchanged. - If orUntilEnd is true, it returns source, and then sets source to null.

slice
T[] slice(T[] arr, size_t p0, size_t p1)

Slices an array. Throws an Exception (not an Error) on out-of-bounds, even in release builds.

sliceIndex
size_t sliceIndex(in T[] arr, in T[] slice)

Given an array and its slice, returns the start index of the slice inside the array.

splitEmpty
auto splitEmpty(T value, S separator)

Like std.array.split, but returns null if val was empty.

toArray
T[] toArray(ref T v)

Slice a variable.

Properties

bytes
inout(ubyte)[] bytes [@property getter]
inout(ubyte)[] bytes [@property getter]

Return the value represented as an array of bytes.

Structs

NormalizedArray
struct NormalizedArray(T, alias normalize)

Array with normalized comparison and hashing.

Meta

Authors

Vladimir Panteleev <vladimir@thecybershadow.net>

License

This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.