-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
1. Updated `seq` library to add functions that are used for manipulating sequenced data structures including string and array. These functions are: `contains`, `has_prefix`, `has_suffix`, `sub`, `split` and `join`. 2. Changed some APIs signature, like changed `//seq.sub(subject, old, new)` to `//seq.sub(old, new, subject)`. It can help to support following code: ``` let rmspace = //seq.sub(" ", ""); rmspace("hello world"), rmspace("a b c")] ```
- Loading branch information
1 parent
c9f4306
commit 8cbfbb2
Showing
22 changed files
with
962 additions
and
177 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,21 +1,101 @@ | ||
# seq | ||
|
||
The `seq` library contains functions that are used for string manipulations. | ||
The `seq` library contains functions that are used for manipulating sequenced data structures including string and array. | ||
|
||
## `//seq.concat(seqs <: array) <: array` <br/> `concat(seqs <: string) <: string` | ||
## `//seq.concat(seqs <: array) <: array` <br/> `//seq.concat(seqs <: string) <: string` | ||
|
||
`concat` takes an array of sequences `seqs` and returns a sequence that is | ||
the concatenation of the sequences in the array. | ||
|
||
Usage: | ||
| example | equals | | ||
|:-|:-| | ||
| `//seq.concat(["ba", "na", "na"])` | `"banana"` | | ||
| `//seq.concat([[1, 2], [3, 4, 5]])` | `[1, 2, 3, 4, 5]` | | ||
|
||
## `//seq.repeat(n <: number, seq <: array) <: array` <br/> `repeat(n <: number, seq <: string) <: string` | ||
## `//seq.contains(sub <: array, subject <: array) <: bool` <br/> `//seq.contains(sub <: string, subject <: string) <: bool` | ||
|
||
`contains` checks whether sequence `sub` is contained in sequence `subject` and returns true if it is, or false otherwise. | ||
|
||
Usage: | ||
| example | equals | | ||
|:-|:-| | ||
| `//seq.contains("substring", "the full string which has substring")` | `true` | | ||
| `//seq.contains("microwave", "just some random sentence")` | `false` | | ||
| `//seq.contains([1,2,3,4,5], [1,2,3,4,5])` | `true` | | ||
| `//seq.contains([['B','C']],[['A', 'B'], ['B','C'],['D','E']])` | `true` | | ||
|
||
## `//seq.has_prefix(prefix <: array, subject <: array) <: bool` <br/> `//seq.has_prefix(prefix <: string, subject <: string) <: bool` | ||
|
||
`has_prefix` checks whether the sequence `subject` is prefixed by sequence `prefix` and returns true if it is, or false otherwise. | ||
|
||
Usage: | ||
| example | equals | | ||
|:-|:-| | ||
| `//seq.has_prefix("I'm", "I'm running out of stuff to write")` | `true` | | ||
| `//seq.has_prefix("to write", "I'm running out of stuff to write")` | `false` | | ||
| `//seq.has_prefix(['A'],['A','B','C'])` | `true` | | ||
| `//seq.has_prefix([1, 2],[1, 2, 3])` | `true` | | ||
| `//seq.has_prefix([[1, 2]],[[1, 2], [3]])` | `true` | | ||
|
||
|
||
## `//seq.has_suffix(suffix <: array, subject <: array) <: bool` <br/> `//seq.has_suffix(suffix <: string, subject <: string) <: bool` | ||
|
||
`has_suffix` checks whether the sequence `subject` is suffixed by sequence `suffix` and returns true if it is, or false otherwise. | ||
|
||
Usage: | ||
| example | equals | | ||
|:-|:-| | ||
| `//seq.has_suffix("I'm", "I'm running out of stuff to write")` | `false` | | ||
| `//seq.has_suffix("to write", "I'm running out of stuff to write")` | `true` | | ||
| `//seq.has_suffix(['E'],['A','B','C','D','E'])` | `true` | | ||
| `//seq.has_suffix([[3, 4]],[[1 ,2], [3, 4]])` | `true` | | ||
|
||
## `//seq.join(joiner <: array, subject <: array) <: array` <br/> `//seq.join(joiner <: string, subject <: array_of_string) <: string` | ||
|
||
`join` returns a concatenated sequence with each member of sequence `subject` delimited by sequence `joiner` | ||
|
||
Usage: | ||
| example | equals | | ||
|:-|:-| | ||
| `//seq.join(", ", ["pew", "another pew", "and more pews"])` | `"pew, another pew, and more pews"` | | ||
| `//seq.join(" ", ["this", "is", "a", "sentence"])` | `"this is a sentence"` | | ||
| `//seq.join(["", "this", "is", "a", "sentence"])` | `"thisisasentence"` | | ||
| `//seq.join([0], [[1, 2], [3, 4], [5, 6]]` | `[1, 2, 0, 3, 4, 0, 5, 6]` | ||
| `//seq.join([0], [[2, [3, 4]], [5, 6]])` | `[2, [3, 4], 0, 5, 6]` | | ||
| `//seq.join([[0],[1]], [[[1, 2], [3, 4]],[[5, 6],[7, 8]]])` | `[[1, 2], [3, 4], [0], [1], [5, 6], [7, 8]]` | | ||
|
||
## `//seq.split(delimiter <: array, subject <: array) <: array` <br/> `//seq.split(delimiter <: string, subject <: string) <: array of string` | ||
|
||
`split` splits sequence `subject` based on the provided sequence `delimiter`. It returns an array of sequence which are split from the sequence `subject`. | ||
|
||
Usage: | ||
| example | equals | | ||
|:-|:-| | ||
| `//seq.split(" ", "deliberately adding spaces to demonstrate the split function")` | `["deliberately", "adding", "spaces", "to", "demonstrate", "the", "split", "function"]` | | ||
| `//seq.split("random stuff", "this is just a random sentence")` | `["this is just a random sentence"]` | | ||
| `//seq.split([1],[1, 2, 3])` | `[[],[2,3]]` | | ||
| `//seq.split([3],[1, 2, 3])` | `[[1,2],[]]` | | ||
| `//seq.split(['A'],['B', 'A', 'C', 'A', 'D', 'E'])` | `[['B'],['C'], ['D', 'E']]` | | ||
| `//seq.split([['C','D'],['E','F']],[['A','B'], ['C','D'], ['E','F'], ['G']])`) | `[[['A','B']], [['G']]]` | | ||
|
||
## `//seq.sub(old <: array, new <: array, subject <: array) <: array` <br/> `//seq.sub(old <: string, new <: string, subject <: string) <: string` | ||
|
||
`sub` replaces occurrences of sequence `old` in sequence `subject` with sequence `new`. It returns the modified sequence. | ||
|
||
Usage: | ||
| example | equals | | ||
|:-|:-| | ||
| `//seq.sub("old string", "new sentence", "this is the old string")` | `"this is the new sentence"` | | ||
| `//seq.sub("string", "stuff", "just another sentence")` | `"just another sentence"` | | ||
| `//seq.sub([1], [2], [1, 2, 3])` | `[2, 2, 3]` | | ||
| `//seq.sub([[2,2]], [[4,4]], [[1,1], [2,2], [3,3]])`| `[[1,1], [4,4], [3,3]]` | | ||
|
||
## `//seq.repeat(n <: number, seq <: array) <: array` <br/> `//seq.repeat(n <: number, seq <: string) <: string` | ||
|
||
`repeat` returns a sequence that contains `seq` repeated `n` times. | ||
|
||
Usage: | ||
| example | equals | | ||
|:-|:-| | ||
| `//seq.repeat(2, "hots")` | `"hotshots"` | |
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
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.