danieldietrich on v1.0.0
Fixes malformed .travis.yml (#2… (compare)
danieldietrich on v1.0.0
Simplification (#2367) (compare)
danieldietrich on travis-yml-fix
Fixes malformed .travis.yml (compare)
.check(100, 1000)
? it sounds like it should tell the underlying generator to generate Long values between -100 and 100 but my custom generator is supposed to generate number either equal to 0 or between 1 and Long.MAX_VALUE
Hi,
Gen is random -> T
, Arbitrary is size -> Gen
, which is size -> random -> T
.
Gen.arbitrary()
creates a 'default' Arbitrary instance that ignores the size argument.
You could do the following:
Arbitrary<Long> validAmounts = size -> Gen.frequency(newArrayList(
Tuple.of(33, Gen.of(0L)),
Tuple.of(67, size)
));
(Note: This was from the top of my head, haven't tested it)
This is the way to go:
Arbitrary<Long> validAmounts = size -> Gen.frequency(
Tuple.of(33, Gen.of(0L)),
Tuple.of(67, Gen.choose(0L, (long) size))
);
Property.def("test").forAll(validAmounts).suchThat(longVal -> true).check(/*size*/100, /*tries*/1000);
However, the Arbitrary size parameter is of type int, if you want to expand it to long space you have to multiply the size in the Gen.choose argument.
then(add2.apply(4)).isEqualTo(6);
Iterable
to a Javaslang Traversable
, use javaslang.collection.Stream.ofAll(Iterable)
. This way you can use Traversable.find()
, Stream
being Traversable
. Going from Iterable
to Stream
should be cheap as Stream
is lazy.
Function
and PartialFunction
are not compatible from the point of view of Liskov substitution principle, so I think the solution 5 would be the correct one to implement. They would, if PartialFunction
would be at the top of the hierarchy, but you can't do that with j.u.l.Function
being part of the hierarchy.
@melston yes, that is true. We should not violate the Liskov Substitution Principle (LSP) and we need strong behavioral subtyping. As @nfekete mentioned, variant 1 of the blog post would be an example of correct strong behavioral substyping - if there only were PartialFunction and Function1. All variants suffer from j.u.f.Function being on top of the type hierarchy. So PartialFunction has to be on its own. Especially we would violate LSP if PartialFunction would extend Function1 (variant 3).
I think I will update the post and mention the LSP. It is the key to understand why the problems arise. Thank you both!!
Hi @iferca, the question arose two days ago (see above). I wrote:
I'm afraid, I think this is only possible with wrapping variables in a separate Bean. We wanted to increase the limit of 8 to something greater (e.g. 22) but our javaslang-gwt blew up, so we currently stay with the limit of 8 (Tuple8, Function8, ...)
The concept of deferred computation is built into two types: Lazy (for lazy evaluation) and Future (for asynchronous computation). I.e. Validation does work synchronously.
Todo: We should find a way to go beyond the limit of 8 variables by investigating how to build Validator hierarchies...
@iferca An Iterable has element of one type T. But generally we have inputs of different types T1, T2, T3, ... The only solution is to use a heterogenous list (HList), see #237.
But I'm afraid - that approach does not seem to be practicable:
// A lot of type annotation
final HAppend<HNil, HCons<Double, HCons<String, HCons<Integer[], HNil>>>,
HCons<Double, HCons<String, HCons<Integer[], HNil>>>> zero = append();
final HAppend<HCons<Boolean, HNil>, HCons<Double, HCons<String, HCons<Integer[], HNil>>>,
HCons<Boolean, HCons<Double, HCons<String, HCons<Integer[], HNil>>>>> one = append(zero);
final HAppend<HCons<Integer, HCons<Boolean, HNil>>, HCons<Double, HCons<String, HCons<Integer[], HNil>>>,
HCons<Integer, HCons<Boolean, HCons<Double, HCons<String, HCons<Integer[], HNil>>>>>> two = append(one);
final HAppend<HCons<String, HCons<Integer, HCons<Boolean, HNil>>>,
HCons<Double, HCons<String, HCons<Integer[], HNil>>>,
HCons<String, HCons<Integer, HCons<Boolean, HCons<Double, HCons<String, HCons<Integer[], HNil>>>>>>>
three = append(two);
isEmpty()
? http://static.javadoc.io/io.javaslang/javaslang/2.1.0-alpha/javaslang/control/Option.html#isEmpty--
yes. so isEmpty()
returns a boolean and then I’ll have to write something like this
if (Option.of(null).isEmpty()) {
System.out.println(“got nothing”);
}
I am wondering if there is a way to pass the stuff that I am doing in the if
as a block.. Java8 Optional
allows me to something like this when the optional value is present. For ex. Optional.of(42).ifPresent(() -> System.out.println(“got something”);
ifPresent()
method of Java8 Optional. @Ramblurr