Skip to content

Commit

Permalink
feat(stdlib): Add isEmpty to List module (#1860)
Browse files Browse the repository at this point in the history
Co-authored-by: Blaine Bublitz <blaine.bublitz@gmail.com>
  • Loading branch information
spotandjake and phated authored Jun 25, 2023
1 parent 49c854e commit 7362189
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
5 changes: 5 additions & 0 deletions compiler/test/stdlib/list.test.gr
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ assert reverse(list) == [3, 2, 1]
assert length([]) == 0
assert length(list) == 3

// List.isEmpty
assert isEmpty([]) == true
assert isEmpty(list) == false
assert isEmpty([1]) == false

// List.append

assert append(list, [4]) == [1, 2, 3, 4]
Expand Down
15 changes: 15 additions & 0 deletions stdlib/list.gr
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,21 @@ provide let length = list => {
iter(0, list)
}

/**
* Determines if the list contains no elements.
*
* @param list: The list to inspect
* @returns `true` if the list is empty and `false` otherwise
*
* @since v0.6.0
*/
provide let isEmpty = list => {
match (list) {
[] => true,
_ => false,
}
}

/**
* Creates a new list with all elements in reverse order.
*
Expand Down
25 changes: 25 additions & 0 deletions stdlib/list.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,31 @@ Returns:
|----|-----------|
|`Number`|The number of elements in the list|

### List.**isEmpty**

<details disabled>
<summary tabindex="-1">Added in <code>next</code></summary>
No other changes yet.
</details>

```grain
isEmpty : (list: List<a>) => Bool
```

Determines if the list contains no elements.

Parameters:

|param|type|description|
|-----|----|-----------|
|`list`|`List<a>`|The list to inspect|

Returns:

|type|description|
|----|-----------|
|`Bool`|`true` if the list is empty and `false` otherwise|

### List.**reverse**

<details disabled>
Expand Down

0 comments on commit 7362189

Please sign in to comment.