StringLikeSequence
优质
小牛编辑
129浏览
2023-12-01
A StringLikeSequence
represents a sequence of characters.
The initial sequence you get by wrapping a string with Lazy(string)
is a StringLikeSequence
.
All methods of StringLikeSequence
that conceptually should return something like a string return another StringLikeSequence
.
Examples
function upcase(str) { return str.toUpperCase(); } Lazy('foo') // instanceof Lazy.StringLikeSequence Lazy('foo').toUpperCase() // instanceof Lazy.StringLikeSequence Lazy('foo').reverse() // instanceof Lazy.StringLikeSequence Lazy('foo').take(2) // instanceof Lazy.StringLikeSequence Lazy('foo').drop(1) // instanceof Lazy.StringLikeSequence Lazy('foo').substring(1) // instanceof Lazy.StringLikeSequence // Note that `map` does not create a `StringLikeSequence` because there's // no guarantee the mapping function will return characters. In the event // you do want to map a string onto a string-like sequence, use // `mapString`: Lazy('foo').map(Lazy.identity) // instanceof Lazy.ArrayLikeSequence Lazy('foo').mapString(Lazy.identity) // instanceof Lazy.StringLikeSequence