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

Add isEmpty and deprecate null #162

Open
wants to merge 2 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` and add deprecation warning for `null` (by @sigma-andex)

Bugfixes:

Expand Down
2 changes: 1 addition & 1 deletion src/Data/String.purs
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ module Data.String

import Data.String.CodePoints

import Data.String.Common (joinWith, localeCompare, null, replace, replaceAll, split, toLower, toUpper, trim)
import Data.String.Common (joinWith, localeCompare, null, isEmpty, replace, replaceAll, split, toLower, toUpper, trim)
import Data.String.Pattern (Pattern(..), Replacement(..))
24 changes: 18 additions & 6 deletions src/Data/String/Common.purs
Original file line number Diff line number Diff line change
@@ -1,27 +1,39 @@
module Data.String.Common
( null
( isEmpty
, joinWith
, localeCompare
, null
, replace
, replaceAll
, split
, toLower
, toUpper
, trim
, joinWith
) where
)
where

import Prelude

import Data.String.Pattern (Pattern, Replacement)
import Prim.TypeError (class Warn, Text)

-- | Returns `true` if the given string is empty.
-- | Returns `true` if the given string is empty. Alias for isEmpty.
-- |
-- | ```purescript
-- | null "" == true
-- | null "Hi" == false
-- | ```
null :: String -> Boolean
null s = s == ""
null :: Warn (Text "'null' is deprecated, use 'isEmpty'") => String -> Boolean
null = isEmpty

-- | Returns `true` if the given string is empty.
-- |
-- | ```purescript
-- | isEmpty "" == true
-- | isEmpty "Hi" == false
-- | ```
isEmpty :: String -> Boolean
isEmpty s = s == ""

-- | Compare two strings in a locale-aware fashion. This is in contrast to
-- | the `Ord` instance on `String` which treats strings as arrays of code
Expand Down
6 changes: 3 additions & 3 deletions test/Test/Data/String.purs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import Test.Assert (assert, assertEqual)
testString :: Effect Unit
testString = do

log "null"
assert $ S.null ""
assert $ not (S.null "a")
log "isEmpty"
assert $ S.isEmpty ""
assert $ not (S.isEmpty "a")

log "stripPrefix"
-- this is a re-export from Data.String.CodeUnits, so the majority of tests are in there
Expand Down