ddash.algorithm

Contains a number of algorithms that operate on sequences. These sequences can be:

<li>value sequences:

assert(1.concat(2, 3, 4).array == [1, 2, 3, 4]);

<li>ranges:

assert(1.concat([2, 3, 4]).array == [1, 2, 3, 4]);

<li>a mixture of the above two:

assert(1.concat([2, 3], 4).array == [1, 2, 3, 4]);

<li>associative arrays:

auto aa = ["a": 1, "b": 0, "c": 2];
assert(aa.compactValues!(a => a == 0) == ["a": 1, "c": 2]);

Furthermore, a number of algorithms allow you to:

<li>operate on members of types:

This would be akin to passing in a predicate that extracts a member variable from a type to operate on instead of operating on the whole type. These algorithms usually have a By prefix:

1 class C {
2     int x;
3 }
4 auto arr1 = [new C(2), new C(3)];
5 auto arr2 = [new C(2), new C(3)];
6 assert(arr1.equalBy!"x"(arr2));

<li>operate via unary or binary predicates:

import std.math: ceil;
assert([2.1, 1.2].difference!ceil([2.3, 3.4]).equal([1.2]));
assert([2.1, 1.2].difference!((a, b) => ceil(a) == ceil(b))([2.3, 3.4]).equal([1.2]));

<li> or both:

1 struct A {
2     int x;
3 }
4 auto arr = [A(4), A(8), A(12)];
5 assert(arr.pullBy!("x", a => a / 2)(5, 9).array == [A(12)]);

Algorithms:

ModuleFunctionsPropertiesDescription
$(DDOX_NAMED_REF ddash.algorithm.compact, `compact`)$(DDOX_NAMED_REF algorithm.compact.compact, `compact`)<br> $(DDOX_NAMED_REF algorithm.compact.compactBy, `compactBy`)<br> $(DDOX_NAMED_REF algorithm.compact.compactValues, `compactValues`)<br>Creates a range or associative array with all null/predicate values removed.
$(DDOX_NAMED_REF ddash.algorithm.concat, `concat`)$(DDOX_NAMED_REF algorithm.concat.concat, `concat`)Concatenates ranges and values together to a new range
$(DDOX_NAMED_REF ddash.algorithm.difference, `difference`)$(DDOX_NAMED_REF algorithm.difference.difference, `difference`)<br> $(DDOX_NAMED_REF algorithm.difference.differenceBy, `differenceBy`)<br>Creates a range of values not included in the other given set of values
$(DDOX_NAMED_REF ddash.algorithm.equal, `equal`)$(DDOX_NAMED_REF algorithm.equal.equal, `equal`)<br> $(DDOX_NAMED_REF algorithm.equal.equalBy, `equalBy`)<br>Tells you if two things are equal
$(DDOX_NAMED_REF ddash.algorithm.fill, `fill`)$(DDOX_NAMED_REF algorithm.fill.fill, `fill`)mutatesAssigns value to each element of input range.
$(DDOX_NAMED_REF ddash.algorithm.flatmap, `flatmap`)$(DDOX_NAMED_REF algorithm.flatmap.flatMap, `flatMap`)Maps and flattens a range.
$(DDOX_NAMED_REF ddash.algorithm.flatten, `flatten`)$(DDOX_NAMED_REF algorithm.flatten.flatten, `flatten`)<br> $(DDOX_NAMED_REF algorithm.flatten.flattenDeep, `flattenDeep`)<br>Flattens a range by removing nesting levels values
$(DDOX_NAMED_REF ddash.algorithm.frompairs, `frompairs`)$(DDOX_NAMED_REF algorithm.frompairs.fromPairs, `fromPairs`)Returns a newly allocated associative array from a range of key/value tuples
$(DDOX_NAMED_REF ddash.algorithm.index, `index`)$(DDOX_NAMED_REF algorithm.index.indexWhere, `indexWhere`)<br> $(DDOX_NAMED_REF algorithm.index.lastIndexWhere, `lastIndexWhere`)<br> $(DDOX_NAMED_REF algorithm.index.indexOf, `indexOf`)<br> $(DDOX_NAMED_REF algorithm.index.lastIndexOf, `lastIndexOf`)<br>Returns optional index of an element in a range.
$(DDOX_NAMED_REF ddash.algorithm.intersection, `intersection`)$(DDOX_NAMED_REF algorithm.intersection, `intersection`)Creates a range of unique values that are included in the other given set of values
$(DDOX_NAMED_REF ddash.algorithm.pull, `pull`)$(DDOX_NAMED_REF algorithm.pull.pull, `pull`)<br> $(DDOX_NAMED_REF algorithm.pull.pullAt, `pullAt`)<br> $(DDOX_NAMED_REF algorithm.pull.pullBy, `pullBy`)<br>Pulls elements out of a range
$(DDOX_NAMED_REF ddash.algorithm.remove, `remove`)$(DDOX_NAMED_REF algorithm.remove.remove, `remove`)mutatesRemoved elements from a range by unary predicate
$(DDOX_NAMED_REF ddash.algorithm.reverse, `reverse`)$(DDOX_NAMED_REF algorithm.reverse.reverse, `reverse`)mutatesReverses a range in place
$(DDOX_NAMED_REF ddash.algorithm.sort, `sort`)$(DDOX_NAMED_REF algorithm.sort.sortBy, `sortBy`)<br> $(DDOX_NAMED_REF algorithm.sort.maybeSort, `maybeSort`)<br> $(DDOX_NAMED_REF algorithm.sort.maybeSortBy, `maybeSortBy`)Provides various ways for sorting a range
$(DDOX_NAMED_REF ddash.algorithm.stringify, `stringify`)$(DDOX_NAMED_REF algorithm.stringify.stringify, `stringify`)<br> $(DDOX_NAMED_REF algorithm.stringify.stringifySeperatedBy, `stringifySeperatedBy`)<br>Converts all elements in range into a string separated by separator.
$(DDOX_NAMED_REF ddash.algorithm.zip, `zip`)$(DDOX_NAMED_REF algorithm.zip.zipEach, `zipEach`)Zips up ranges together

Modules

compact
module ddash.algorithm.compact

Compacts a range

concat
module ddash.algorithm.concat

Create a new range concatenating input range/value with any additional ranges and/or values.

difference
module ddash.algorithm.difference

Creates a range of values not included in the other given ranges.

equal
module ddash.algorithm.equal

Tells you if two things are equal

fill
module ddash.algorithm.fill

Assigns value to each element of input range range

flatmap
module ddash.algorithm.flatmap

Flatmaps a range

flatten
module ddash.algorithm.flatten

Flattens a range one level deep by removing non truthy values.

frompairs
module ddash.algorithm.frompairs

Returns a newly allocated associative array from pairs

index
module ddash.algorithm.index

Returns an optional index of an element.

intersection
module ddash.algorithm.intersection

Creates a range of unique values that are included in all given ranges

pull
module ddash.algorithm.pull

Removes elements from a range

remove
module ddash.algorithm.remove

Removes elements from a range

reverse
module ddash.algorithm.reverse

Reverses the range by mutating it

sort
module ddash.algorithm.sort

sorts stuff

stringify
module ddash.algorithm.stringify

Converts all elements in range into a string separated by separator.

zip
module ddash.algorithm.zip

Zips up ranges up together

Meta