Closed sageserpent-open closed 2 years ago
While we at at, let's have this too, inspired by Vavr....
final Trials<ImmutableSet<Integer>> immutableSets = api.integers.immutableSets().covariantly()
final Trials<Set<Integer>> sets = immutableSets
Not sure if this is possible given the limitations of Java's type system, as the wildcard would be at the top level of the type...
First casualty - as long as a common implementation underpins both the Java and Scala forms of Trials
, then we can't have competing declarations of Trials.options
- different return types. For now, the end user will have to map a Trials.optionals
using <optionals>.map(Option::fromOptional)
.
Sorry.
Also dropped is the Trials.covariantly
- just use a wildcard type, grin and bear it:
final Trials<? extends Set<Integer>> narrowed = api.integers().immutableSortedSets(Integer::compare);
Proof from JShell:
import com.sageserpent.americium.java.Trials;
import java.util.Collection;
final Trials<? extends Collection<Integer>>
narrowed = Trials.api().integers().immutableSortedSets(Integer::compare);
narrowed.withLimit(3).supplyTo(System.out::println);
narrowed.map(Object::getClass).withLimit(3).supplyTo(System.out::println);
Output:
import com.sageserpent.americium.java.Trials
import java.util.Collection
field Trials<? extends Collection<Integer>> narrowed = TrialsImplementation(Free(...))
narrowed.withLimit(3).supplyTo(System.out::println)
[-1975667456, -54163312]
[]
[1610305737]
narrowed.map(Object::getClass).withLimit(3).supplyTo(System.out::println)
class com.google.common.collect.RegularImmutableSortedSet
class com.google.common.collect.RegularImmutableSortedSet
class com.google.common.collect.RegularImmutableSortedSet
This is available in release 1.2.5 .
What it says on the tin - syntax like this:
trialsOfX.options
- ScalaTrials[Option[X]]
trialsOfLeft.or(trialsOfRight)
- ScalaTrials[Either[Left, Right]]
trialsOfX.options
- JavaTrials<Option<X>>
- the CyclopsOption
.trialsOfX.optionals
- JavaTrials<Optional<X>>
- standard JavaOptional
.trialsOfLeft.or(trialsOfRight)
- JavaTrials<Either<Left, Right>>
- CyclopsEither
.