-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Track positions for input streams and clean up unnecessary keywords
- Loading branch information
1 parent
2abee7f
commit b2c8ca6
Showing
32 changed files
with
220 additions
and
170 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,20 @@ | ||
package jcombinators.data; | ||
|
||
public final record Tuple<A, B>(A first, B second) { | ||
import java.util.function.BiFunction; | ||
import java.util.function.Function; | ||
|
||
public record Tuple<A, B>(A first, B second) { | ||
|
||
public <C, D> Tuple<C, D> map(final Function<A, C> firstFunction, final Function<B, D> secondFunction) { | ||
return of(firstFunction.apply(first), secondFunction.apply(second)); | ||
} | ||
|
||
public <C> C fold(final BiFunction<A, B, C> function) { | ||
return function.apply(first, second); | ||
} | ||
|
||
public static <A, B> Tuple<A, B> of(final A first, final B second) { | ||
return new Tuple<>(first, second); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package jcombinators.input; | ||
|
||
public final class InputWrapper implements CharSequence { | ||
|
||
private Input input; | ||
|
||
public InputWrapper(final Input input) { | ||
this.input = input; | ||
} | ||
|
||
@Override | ||
public int length() { | ||
return input.contents.length() - input.offset; | ||
} | ||
|
||
@Override | ||
public char charAt(final int index) { | ||
return input.contents.charAt(index + input.offset); | ||
} | ||
|
||
@Override | ||
public CharSequence subSequence(final int start, final int end) { | ||
return input.contents.substring(start + input.offset, end + input.offset); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.