Skip to content

Commit

Permalink
#234 Updated docs and added more test cases..
Browse files Browse the repository at this point in the history
  • Loading branch information
ericzhang6222 committed May 20, 2020
1 parent 3211949 commit 07ba2e5
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 0 deletions.
74 changes: 74 additions & 0 deletions docs/std-seq.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

The `seq` library contains functions that are used for manipulating sequenced data structures.

## String

## `//seq.concat(seqs <: array) <: array` <br/> `concat(seqs <: string) <: string`

`concat` takes an array of sequences `seqs` and returns a sequence that is
Expand Down Expand Up @@ -90,3 +92,75 @@ Usage:
| `//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"]` |

## Array

## `//seq.has_prefix(prefix <: array, subject <: array) <: bool`

`has_prefix` checks whether the array `subject` is prefixed by array `prefix`. It returns a boolean.

Usage:

| example | equals |
|:-|:-|
| `//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`

`has_suffix` checks whether the array `subject` is suffixed by array `suffix`. It returns a boolean.

Usage:

| example | equals |
|:-|:-|
| `//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`

`join` returns a concatenated array with each member of `subject` delimited by `joiner`

Usage:

| example | equals |
|:-|:-|
| `//seq.join([0], [1,2,3,4,5])` | `[1,0,2,0,3,0,4,0,5]` |
| `//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.contains(sub <: array, subject <: array) <: bool`

`contains` checks whether array `sub` is contained in array `subject`. It returns a boolean.

Usage:

| example | equals |
|:-|:-|
| `//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.sub(old <: array, new <: array, subject <: array) <: array`

`new` replaces occurrences of array `old` in array `subject` with array `new`. It returns the modified array.

Usage:

| example | equals |
|:-|:-|
| `//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.split(delimiter <: array, subject <: array) <: array`

`split` splits the array `subject` based on the provided array `delimiter`. It returns an array
which are split from the array `subject`.

Usage:

| example | equals |
|:-|:-|
| `//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']]]` |
3 changes: 3 additions & 0 deletions syntax/std_seq_prefix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ func TestArrayPrefix(t *testing.T) {
AssertCodesEvalToSameValue(t, `false`, `//seq.has_prefix(['A','B','C','D','E','F'],['A','B','C','D','E'])`)
AssertCodesEvalToSameValue(t, `false`, `//seq.has_prefix(['A','B','C','D','E','F'],['A','B','C','D','E'])`)

AssertCodesEvalToSameValue(t, `true`, `//seq.has_prefix([1, 2],[1, 2, 3])`)
AssertCodesEvalToSameValue(t, `true`, `//seq.has_prefix([[1, 2]],[[1, 2], [3]])`)

AssertCodesEvalToSameValue(t, `true`, `//seq.has_prefix([], [])`)
AssertCodesEvalToSameValue(t, `false`, `//seq.has_prefix(['A','B','C','D','E','F'],[])`)
AssertCodesEvalToSameValue(t, `true`, `//seq.has_prefix([],['A','B','C','D','E'])`)
Expand Down
2 changes: 2 additions & 0 deletions syntax/std_seq_suffix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ func TestArraySuffix(t *testing.T) {
AssertCodesEvalToSameValue(t, `false`, `//seq.has_suffix(['C','D'],['A','B','C','D','E'])`)
AssertCodesEvalToSameValue(t, `false`, `//seq.has_suffix(['A','B','C','D','E','F'],['A','B','C','D','E'])`)

AssertCodesEvalToSameValue(t, `true`, `//seq.has_suffix([[3, 4]],[[1 ,2], [3, 4]])`)

AssertCodesEvalToSameValue(t, `true`, `//seq.has_suffix([],['A','B','C','D','E'])`)
AssertCodesEvalToSameValue(t, `true`, `//seq.has_suffix([], [])`)
AssertCodesEvalToSameValue(t, `false`, `//seq.has_suffix(['D','E'],[])`)
Expand Down

0 comments on commit 07ba2e5

Please sign in to comment.