Skip to content

Commit

Permalink
doc: Add ops
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmah309 committed Jul 7, 2024
1 parent 6002652 commit 79d496e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 19 deletions.
1 change: 1 addition & 0 deletions book/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
# Minor Libraries

- [convert](./libs/convert/convert.md)
- [ops](./libs/ops/ops.md)
- [panic](./libs/panic/panic.md)

# Miscellaneous
Expand Down
21 changes: 2 additions & 19 deletions book/src/libs/array/array.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,10 @@
var array = Arr(null, 10);
array = Arr.constant(const [1,2,3,4,5]);
array = Arr.generate(10, (i) => i);
array = Arr.range(0, 10, step: 2);
for(final entry in array){
// do something
}
var (slice1, slice2) = array.splitSlice(3);
```
`Arr`'s allocation will be more efficient than compared to a `List` since it does not reserve additional capacity and allocates the full amount eagerly. Which is important since allocations account for most of the cost of the runtime costs of a List.

## Range

`range` is a convenience function for an iterator over the range `[start..end)`, where `start >= end` or `start <= end`.
```dart
for(final x in range(0, 10).stepBy(2)){
// code
}
// or equivalent
for(final x in (0, 10).stepBy(2)){
// code
}
```

`rangeArr` also exists as a more efficient method for when it is known collecting the range is needed.
```dart
Arr<int> x = rangeArr(0, 10, step: 2);
```
`Arr`'s allocation will be more efficient than compared to a `List` since it does not reserve additional capacity and allocates the full amount eagerly. Which is important since allocations account for most of the cost of the runtime costs of a List.
15 changes: 15 additions & 0 deletions book/src/libs/ops/ops.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Ops

## Range

`range` is a convenience function for an iterator over the range `[start..end)`, where `start >= end` or `start <= end`.
```dart
for(final x in range(0, 10).stepBy(2)){
// code
}
// or equivalent
for(final x in (0, 10).stepBy(2)){
// code
}
```
Note `Arr.range(..)` also exists as a more efficient method for when it is known collecting the range is needed.

0 comments on commit 79d496e

Please sign in to comment.