Package at.jku.ssw.fp.sect11_3.check4j
Interface Gen<A>
-
- Type Parameters:
A
- the type of the generated values
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
@FunctionalInterface public interface Gen<A>
Functional interface for random value generators. Random value generators form a monad.- Author:
- Herbert Praehofer
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default Gen<A>
filter(Predicate<? super A> pred)
Filters the value of this generator.default <B> Gen<B>
flatMap(Function<? super A,Gen<? extends B>> fn)
Creates a generator which generates values which are created by mapping the values from this generator using the mapping function.default <B> Gen<B>
map(Function<? super A,? extends B> fn)
Creates a generator which generates values which are created by mapping the values from this generator using the mapping function.static <A> Gen<A>
of(A a)
Creates a generator returning the provided value.A
sample()
Returns a new random value.default Stream<A>
stream()
Returns a stream of random values.
-
-
-
Method Detail
-
sample
A sample()
Returns a new random value.- Returns:
- the new random value
-
stream
default Stream<A> stream()
Returns a stream of random values.- Returns:
- the stream of random values
-
of
static <A> Gen<A> of(A a)
Creates a generator returning the provided value.- Type Parameters:
A
- the type of the returned value- Parameters:
a
- the constant value to return- Returns:
- the constant value
-
map
default <B> Gen<B> map(Function<? super A,? extends B> fn)
Creates a generator which generates values which are created by mapping the values from this generator using the mapping function.- Type Parameters:
B
- the type of mapped value- Parameters:
fn
- the mapping function- Returns:
- the generator for the mapped values
-
flatMap
default <B> Gen<B> flatMap(Function<? super A,Gen<? extends B>> fn)
Creates a generator which generates values which are created by mapping the values from this generator using the mapping function.- Type Parameters:
B
- the type of mapped value- Parameters:
fn
- the mapping function- Returns:
- the generator for the mapped values
-
filter
default Gen<A> filter(Predicate<? super A> pred)
Filters the value of this generator. If the value generated by this generator is not accepted by the predicate, a new value is generated by this generator.- Parameters:
pred
- the testing function- Returns:
- the generator only generating values accepted by the predicate
-
-