dev.marksman.composablerandom.Collections Maven / Gradle / Ivy
package dev.marksman.composablerandom;
import dev.marksman.collectionviews.ImmutableNonEmptyVector;
import dev.marksman.collectionviews.ImmutableVector;
import dev.marksman.collectionviews.NonEmptyVector;
import java.util.*;
import static com.jnape.palatable.lambda.functions.builtin.fn2.Zip.zip;
import static dev.marksman.composablerandom.Generator.*;
class Collections {
static Generator> generateList(Generator g) {
return sized(n -> buildArrayList(n, g));
}
static Generator> generateNonEmptyList(Generator g) {
return sized(n -> buildArrayList(Math.max(1, n), g));
}
static Generator> generateListOfN(int n, Generator g) {
if (n < 0) {
throw new IllegalArgumentException("n must be >= 0");
}
return buildArrayList(n, g);
}
static Generator> generateSet(Generator g) {
return sized(n -> buildHashSet(n, g));
}
static Generator> generateNonEmptySet(Generator g) {
return sized(n -> buildHashSet(Math.max(1, n), g));
}
static Generator> generateVector(Generator g) {
return sized(n -> buildVector(n, g));
}
static Generator> generateNonEmptyVector(Generator g) {
return sized(n -> buildNonEmptyVector(Math.max(1, n), g));
}
static Generator> generateVectorOfN(int n, Generator g) {
if (n < 0) {
throw new IllegalArgumentException("n must be >= 0");
}
return buildVector(n, g);
}
static Generator> generateNonEmptyVectorOfN(int n, Generator g) {
if (n < 1) {
throw new IllegalArgumentException("n must be >= 1");
}
return buildNonEmptyVector(n, g);
}
static Generator