Package fj.data
Class LazyString
java.lang.Object
fj.data.LazyString
- All Implemented Interfaces:
CharSequence
A lazy (non-evaluated) immutable character string.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final LazyString
The empty string.static final F
<Stream<Character>, LazyString> First-class conversion from character streams to lazy strings.static final F
<LazyString, Stream<Character>> First-class conversion from lazy strings to streams.static final F
<LazyString, String> First-class conversion from lazy strings to String. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionappend
(LazyString cs) Appends the given lazy string to the end of this lazy string.Appends the given String to the end of this lazy string.bind
(F<Character, LazyString> f) char
charAt
(int index) Returns the caracter at the specified index.boolean
contains
(LazyString cs) Returns true if the given lazy string is a substring of this lazy string.boolean
endsWith
(LazyString cs) Returns true if the given lazy string is a suffix of this lazy string.eval()
static LazyString
Constructs a lazy string from a stream of characters.char
head()
Returns the first character of this string.indexOf
(char c) Returns the first index of the given character in this lazy string, if present.indexOf
(LazyString cs) Returns the first index of the given substring in this lazy string, if present.boolean
isEmpty()
Checks if this string is empty.int
length()
The length of the lazy string.lines()
Splits this lazy string into lines.static F
<LazyString, Stream<LazyString>> lines_()
boolean
Regular expression pattern matching.reverse()
Returns the reverse of this string.split
(char c) Splits this lazy string by the given delimiter character.Splits this lazy string by characters matching the given predicate.static F
<LazyString, F<LazyString, Boolean>> First-class prefix check.boolean
startsWith
(LazyString cs) Returns true if the given lazy string is a prefix of this lazy string.static LazyString
Constructs a lazy string from a String.subSequence
(int start, int end) Gets the specified subsequence of this lazy string.tail()
Returns all but the first character of this string.toStream()
Gives a stream representation of this lazy string.toString()
Returns the String representation of this lazy string.static LazyString
unlines
(Stream<LazyString> str) Joins the given stream of lazy strings into one, separated by newlines.static F
<Stream<LazyString>, LazyString> unlines_()
static LazyString
unwords
(Stream<LazyString> str) Joins the given stream of lazy strings into one, separated by spaces.words()
Splits this lazy string into words by spaces.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.CharSequence
chars, codePoints
-
Field Details
-
s
-
empty
The empty string. -
toStream
First-class conversion from lazy strings to streams. -
toString
First-class conversion from lazy strings to String. -
fromStream
First-class conversion from character streams to lazy strings. -
eqS
-
-
Constructor Details
-
LazyString
-
-
Method Details
-
str
Constructs a lazy string from a String.- Parameters:
s
- A string from which to construct a lazy string.- Returns:
- A lazy string with the characters from the given string.
-
fromStream
Constructs a lazy string from a stream of characters.- Parameters:
s
- A stream of characters.- Returns:
- A lazy string with the characters from the given stream.
-
toStream
Gives a stream representation of this lazy string.- Returns:
- A stream representation of this lazy string.
-
length
public int length()The length of the lazy string. Note that this operation is O(n).- Specified by:
length
in interfaceCharSequence
- Returns:
- The length of this lazy string.
-
charAt
public char charAt(int index) Returns the caracter at the specified index.- Specified by:
charAt
in interfaceCharSequence
- Parameters:
index
- The index for the character to be returned.- Returns:
- The character at the specified index.
-
subSequence
Gets the specified subsequence of this lazy string. This operation does not fail for indexes that are out of bounds. If the start index is past the end of this lazy string, then the resulting character sequence will be empty. If the end index is past the end of this lazy string, then the resulting character sequence will be truncated.- Specified by:
subSequence
in interfaceCharSequence
- Parameters:
start
- The character index of this lazy string at which to start the subsequence.end
- The character index of this lazy string at which to end the subsequence.- Returns:
- A character sequence containing the specified character subsequence.
-
toStringEager
Returns the String representation of this lazy string.- Returns:
- The String representation of this lazy string.
-
toStringLazy
-
toString
- Specified by:
toString
in interfaceCharSequence
- Overrides:
toString
in classObject
-
eval
-
append
Appends the given lazy string to the end of this lazy string.- Parameters:
cs
- A lazy string to append to this one.- Returns:
- A new lazy string that is the concatenation of this string and the given string.
-
append
Appends the given String to the end of this lazy string.- Parameters:
s
- A String to append to this lazy string.- Returns:
- A new lazy string that is the concatenation of this lazy string and the given string.
-
contains
Returns true if the given lazy string is a substring of this lazy string.- Parameters:
cs
- A substring to find in this lazy string.- Returns:
- True if the given string is a substring of this string, otherwise False.
-
endsWith
Returns true if the given lazy string is a suffix of this lazy string.- Parameters:
cs
- A string to find at the end of this lazy string.- Returns:
- True if the given string is a suffix of this lazy string, otherwise False.
-
startsWith
Returns true if the given lazy string is a prefix of this lazy string.- Parameters:
cs
- A string to find at the start of this lazy string.- Returns:
- True if the given string is a prefix of this lazy string, otherwise False.
-
startsWith
First-class prefix check.- Returns:
- A function that yields true if the first argument is a prefix of the second.
-
head
public char head()Returns the first character of this string.- Returns:
- The first character of this string, or error if the string is empty.
-
tail
Returns all but the first character of this string.- Returns:
- All but the first character of this string, or error if the string is empty.
-
isEmpty
public boolean isEmpty()Checks if this string is empty.- Specified by:
isEmpty
in interfaceCharSequence
- Returns:
- True if there are no characters in this string, otherwise False.
-
reverse
Returns the reverse of this string.- Returns:
- the reverse of this string.
-
indexOf
Returns the first index of the given character in this lazy string, if present.- Parameters:
c
- A character to find in this lazy string.- Returns:
- The first index of the given character in this lazy string, or None if the character is not present.
-
indexOf
Returns the first index of the given substring in this lazy string, if present.- Parameters:
cs
- A substring to find in this lazy string.- Returns:
- The first index of the given substring in this lazy string, or None if there is no such substring.
-
matches
Regular expression pattern matching.- Parameters:
regex
- A regular expression to match this lazy string.- Returns:
- True if this string mathches the given regular expression, otherwise False.
-
split
Splits this lazy string by characters matching the given predicate.- Parameters:
p
- A predicate that matches characters to be considered delimiters.- Returns:
- A stream of the substrings in this lazy string, when separated by the given predicate.
-
map
-
bind
-
split
Splits this lazy string by the given delimiter character.- Parameters:
c
- A delimiter character at which to split.- Returns:
- A stream of substrings of this lazy string, when separated by the given delimiter.
-
words
Splits this lazy string into words by spaces.- Returns:
- A stream of the words in this lazy string, when split by spaces.
-
lines
Splits this lazy string into lines.- Returns:
- A stream of the lines in this lazy string, when split by newlines.
-
lines_
-
unlines
Joins the given stream of lazy strings into one, separated by newlines.- Parameters:
str
- A stream of lazy strings to join by newlines.- Returns:
- A new lazy string, consisting of the given strings separated by newlines.
-
unlines_
-
unwords
Joins the given stream of lazy strings into one, separated by spaces.- Parameters:
str
- A stream of lazy strings to join by spaces.- Returns:
- A new lazy string, consisting of the given strings with spaces in between.
-