Skip to content

Add isEmpty #222

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Notable changes to this project are documented in this file. The format is based
Breaking changes:

New features:
- Add `isEmpty` (#222 by @sigma-andex)

Bugfixes:

Expand Down
13 changes: 11 additions & 2 deletions src/Data/Array.purs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ module Data.Array
, many

, null
, isEmpty
, length

, (:), cons
Expand Down Expand Up @@ -217,13 +218,21 @@ many v = some v <|> pure []
-- Array size ------------------------------------------------------------------
--------------------------------------------------------------------------------

-- | Test whether an array is empty.
-- | Test whether an array is empty. Alias for `isEmpty`.
-- | ```purescript
-- | null [] = true
-- | null [1, 2] = false
-- | ```
null :: forall a. Array a -> Boolean
null xs = length xs == 0
null = isEmpty

-- | Test whether an array is empty.
-- | ```purescript
-- | isEmpty [] = true
-- | isEmpty [1, 2] = false
-- | ```
isEmpty :: forall a. Array a -> Boolean
isEmpty xs = length xs == 0

-- | Get the number of elements in an array.
-- | ```purescript
Expand Down
10 changes: 5 additions & 5 deletions test/Test/Data/Array.purs
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ testArray = do
-- some
-- many

log "null should return false for non-empty arrays"
assert $ A.null [1] == false
assert $ A.null [1, 2, 3] == false
log "isEmpty should return false for non-empty arrays"
assert $ A.isEmpty [1] == false
assert $ A.isEmpty [1, 2, 3] == false

log "null should return true for an empty array"
assert $ A.null nil == true
log "isEmpty should return true for an empty array"
assert $ A.isEmpty nil == true

log "length should return the number of items in an array"
assert $ A.length nil == 0
Expand Down