diff options
| author | Benjamin J. Culkin <bjculkin@mix.wvu.edu> | 2020-11-11 12:23:57 -0400 |
|---|---|---|
| committer | Benjamin J. Culkin <bjculkin@mix.wvu.edu> | 2020-11-11 12:23:57 -0400 |
| commit | 0805c271505340c1da60a1b8920560bae73f21a9 (patch) | |
| tree | 2703917145a8e8aee7bd4ad55634c65ed688dda6 /src/main/java/bjc/data/LazyPair.java | |
| parent | d3239ea7b6945d449c0361416ab54fec6f9643e6 (diff) | |
| parent | c56a10f7c943dd9e9f04854395638babfaba6529 (diff) | |
Merge branch 'master' of https://github.com/bculkin2442/esodata
Diffstat (limited to 'src/main/java/bjc/data/LazyPair.java')
| -rw-r--r-- | src/main/java/bjc/data/LazyPair.java | 66 |
1 files changed, 30 insertions, 36 deletions
diff --git a/src/main/java/bjc/data/LazyPair.java b/src/main/java/bjc/data/LazyPair.java index e668cd4..2481cd7 100644 --- a/src/main/java/bjc/data/LazyPair.java +++ b/src/main/java/bjc/data/LazyPair.java @@ -79,8 +79,7 @@ public class LazyPair<LeftType, RightType> implements IPair<LeftType, RightType> public <BoundLeft> IPair<BoundLeft, RightType> bindLeft(final Function<LeftType, IPair<BoundLeft, RightType>> leftBinder) { final Supplier<LeftType> leftSupp = () -> { - if (leftMaterialized) - return leftValue; + if (leftMaterialized) return leftValue; return leftSupplier.get(); }; @@ -92,8 +91,7 @@ public class LazyPair<LeftType, RightType> implements IPair<LeftType, RightType> public <BoundRight> IPair<LeftType, BoundRight> bindRight( final Function<RightType, IPair<LeftType, BoundRight>> rightBinder) { final Supplier<RightType> rightSupp = () -> { - if (rightMaterialized) - return rightValue; + if (rightMaterialized) return rightValue; return rightSupplier.get(); }; @@ -108,12 +106,14 @@ public class LazyPair<LeftType, RightType> implements IPair<LeftType, RightType> final BiFunction<LeftType, OtherLeft, CombinedLeft> leftCombiner, final BiFunction<RightType, OtherRight, CombinedRight> rightCombiner) { - return otherPair.bind((otherLeft, otherRight) -> bind((leftVal, rightVal) -> { - final CombinedLeft left = leftCombiner.apply(leftVal, otherLeft); - final CombinedRight right = rightCombiner.apply(rightVal, otherRight); - - return new LazyPair<>(left, right); - })); + return otherPair.bind((otherLeft, otherRight) -> { + return bind((leftVal, rightVal) -> { + final CombinedLeft left = leftCombiner.apply(leftVal, otherLeft); + final CombinedRight right = rightCombiner.apply(rightVal, otherRight); + + return new LazyPair<>(left, right); + }); + }); } @Override @@ -142,15 +142,13 @@ public class LazyPair<LeftType, RightType> implements IPair<LeftType, RightType> public <NewLeft> IPair<NewLeft, RightType> mapLeft(final Function<LeftType, NewLeft> mapper) { final Supplier<NewLeft> leftSupp = () -> { - if (leftMaterialized) - return mapper.apply(leftValue); + if (leftMaterialized) return mapper.apply(leftValue); return mapper.apply(leftSupplier.get()); }; final Supplier<RightType> rightSupp = () -> { - if (rightMaterialized) - return rightValue; + if (rightMaterialized) return rightValue; return rightSupplier.get(); }; @@ -162,15 +160,13 @@ public class LazyPair<LeftType, RightType> implements IPair<LeftType, RightType> public <NewRight> IPair<LeftType, NewRight> mapRight(final Function<RightType, NewRight> mapper) { final Supplier<LeftType> leftSupp = () -> { - if (leftMaterialized) - return leftValue; + if (leftMaterialized) return leftValue; return leftSupplier.get(); }; final Supplier<NewRight> rightSupp = () -> { - if (rightMaterialized) - return mapper.apply(rightValue); + if (rightMaterialized) return mapper.apply(rightValue); return mapper.apply(rightSupplier.get()); }; @@ -231,37 +227,35 @@ public class LazyPair<LeftType, RightType> implements IPair<LeftType, RightType> @Override public boolean equals(final Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (!(obj instanceof LazyPair<?, ?>)) - return false; + if (this == obj) return true; + if (obj == null) return false; + if (!(obj instanceof LazyPair<?, ?>)) return false; final LazyPair<?, ?> other = (LazyPair<?, ?>) obj; - if (leftMaterialized != other.leftMaterialized) - return false; + if (leftMaterialized != other.leftMaterialized) return false; if (leftMaterialized) { if (leftValue == null) { - if (other.leftValue != null) - return false; - } else if (!leftValue.equals(other.leftValue)) + if (other.leftValue != null) return false; + } else if (!leftValue.equals(other.leftValue)) { return false; - } else + } + } else { return false; + } - if (rightMaterialized != other.rightMaterialized) - return false; + if (rightMaterialized != other.rightMaterialized) return false; + if (rightMaterialized) { if (rightValue == null) { - if (other.rightValue != null) - return false; - } else if (!rightValue.equals(other.rightValue)) + if (other.rightValue != null) return false; + } else if (!rightValue.equals(other.rightValue)) { return false; - } else + } + } else { return false; + } return true; } |
