Skip to content

Commit a2ba8cb

Browse files
committed
feat!: refactor to support eliding arguments
This commit allows arguments to be omitted when invoking the constructor, thus allowing more concise syntax when creating slices. BREAKING CHANGE: support argument omission Existing code should continue to work as is; however, error handling has changed. One can now create a slice without providing arguments. To adopt the new syntax, one no longer has to explicitly provide `null` for "empty" slice parameters.
1 parent 1f41686 commit a2ba8cb

6 files changed

Lines changed: 566 additions & 197 deletions

File tree

lib/node_modules/@stdlib/slice/ctor/README.md

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,23 +42,40 @@ var Slice = require( '@stdlib/slice/ctor' );
4242

4343
<a name="main"></a>
4444

45-
#### Slice( \[start, ]stop\[, step] )
45+
#### Slice( \[stop] )
4646

4747
Returns a `Slice` instance.
4848

4949
```javascript
50-
var s = new Slice( 0, 10, 1 );
50+
var s = new Slice();
51+
// returns <Slice>
52+
53+
s = new Slice();
54+
// returns <Slice>
55+
```
56+
57+
The constructor accepts the following arguments:
58+
59+
- **stop**: ending index (exclusive). Default: `null`.
60+
61+
#### Slice( start, stop\[, step] )
62+
63+
Returns a `Slice` instance.
64+
65+
```javascript
66+
var s = new Slice( 0, 10 );
67+
// returns <Slice>
68+
69+
s = new Slice( 0, 10, 1 );
5170
// returns <Slice>
5271
```
5372

54-
The constructor has the following parameters:
73+
The constructor accepts the following arguments:
5574

56-
- **start**: starting index (inclusive). Default: `null`.
75+
- **start**: starting index (inclusive).
5776
- **stop**: ending index (exclusive).
5877
- **step**: index increment. Default: `null`.
5978

60-
Slice arguments may be either integers or `null`, where the latter indicates a slice parameter which should be determined based on the slice context (e.g., when used to index into an [`ndarray`][@stdlib/ndarray/ctor]).
61-
6279
* * *
6380

6481
### Properties
@@ -206,6 +223,7 @@ o = s.toJSON();
206223

207224
## Notes
208225

226+
- Slice arguments may be either integers or `null`, where the latter indicates a slice parameter which should be determined based on the slice context (e.g., when used to index into an [`ndarray`][@stdlib/ndarray/ctor]).
209227
- Slice instances have no explicit functionality; however, they are used by [`ndarray`][@stdlib/ndarray] and other packages for creating views into multi-dimensional data structures.
210228

211229
</section>

lib/node_modules/@stdlib/slice/ctor/docs/repl.txt

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,35 @@
11

2-
{{alias}}( [start, ]stop[, step] )
2+
{{alias}}( [stop] )
33
Returns a Slice.
44

55
Parameters
66
----------
7-
start: integer|null (optional)
8-
Starting index (inclusive). Default: null.
7+
stop: integer|null|undefined (optional)
8+
Ending index (exclusive).
99

10-
stop: integer|null
10+
Returns
11+
-------
12+
s: Slice
13+
Slice instance.
14+
15+
Examples
16+
--------
17+
> var s = new {{alias}}();
18+
> s = new {{alias}}( 10 );
19+
20+
21+
{{alias}}( start, stop[, step] )
22+
Returns a Slice.
23+
24+
Parameters
25+
----------
26+
start: integer|null|undefined
27+
Starting index (inclusive).
28+
29+
stop: integer|null|undefined
1130
Ending index (exclusive).
1231

13-
step: integer|null (optional)
32+
step: integer|null|undefined (optional)
1433
Index increment. Default: null.
1534

1635
Returns
@@ -20,8 +39,7 @@
2039

2140
Examples
2241
--------
23-
> var s = new {{alias}}( 10 );
24-
> s = new {{alias}}( 2, 10 );
42+
> var s = new {{alias}}( 2, 10 );
2543
> s = new {{alias}}( 2, 10, 1 );
2644

2745

0 commit comments

Comments
 (0)