fix issues

This commit is contained in:
Yadunand Prem 2022-09-29 17:28:44 +08:00
parent bd2d0766ae
commit d8e797ae3a
3 changed files with 11 additions and 13 deletions

View File

@ -5,9 +5,10 @@
* Contains a single abstract method apply. * Contains a single abstract method apply.
* CS2030S Lab 4 * CS2030S Lab 4
* AY22/23 Semester 1 * AY22/23 Semester 1
*
* @author Yadunand Prem (10B) * @author Yadunand Prem (10B)
*/ */
interface Applicable<T> { interface Applicable<T> {
<R> Applicable<R> apply(Probably<Immutator<R, T>> probablyImmutator); <R> Applicable<R> apply(Probably<? extends Immutator<? extends R, ? super T>> probablyImmutator);
} }

View File

@ -9,5 +9,5 @@
*/ */
interface Immutatorable<T> { interface Immutatorable<T> {
public <R> Immutatorable<R> transform(Immutator<R, T> immutator); public <R> Immutatorable<R> transform(Immutator<? extends R, ? super T> immutator);
} }

View File

@ -41,7 +41,7 @@ class Probably<T> implements Actionable<T>, Immutatorable<T>, Applicable<T> {
* Unless the value is null, then nothing is * Unless the value is null, then nothing is
* given again. * given again.
* *
* @param <T> type T * @param <T> type T
* *
* @param value Probably this is the value * @param value Probably this is the value
* unless it is null then we say * unless it is null then we say
@ -105,21 +105,18 @@ class Probably<T> implements Actionable<T>, Immutatorable<T>, Applicable<T> {
action.call(this.value); action.call(this.value);
} }
public Probably<T> check(IsModEq eq) { public Probably<T> check(Immutator<Boolean, ? super T> eq) {
if (this.value == null) { if (this.value == null) {
return none(); return none();
} }
if (this.value instanceof Integer) { if (eq.invoke(this.value)) {
Integer val = (Integer) this.value; return this;
if (eq.invoke(val)) {
return this;
}
} }
return none(); return none();
} }
@Override @Override
public <R> Probably<R> transform(Immutator<R, T> immutator) { public <R> Probably<R> transform(Immutator<? extends R, ? super T> immutator) {
if (this.value == null) { if (this.value == null) {
return none(); return none();
} }
@ -127,9 +124,9 @@ class Probably<T> implements Actionable<T>, Immutatorable<T>, Applicable<T> {
} }
@Override @Override
public <R> Probably<R> apply(Probably<Immutator<R, T>> probablyImmutator) { public <R> Probably<R> apply(Probably<? extends Immutator<? extends R, ? super T>> probablyImmutator) {
if (this.value != null && probablyImmutator.value != null) { if (probablyImmutator.value != null) {
return just(probablyImmutator.value.invoke(this.value)); return this.transform(probablyImmutator.value);
} }
return none(); return none();
} }