Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(stdlib): Add isEmpty to List module #1860

Merged
merged 3 commits into from
Jun 25, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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