Skip to content

Commit c1d610b

Browse files
martijnbastiaanphadej
authored andcommitted
Add examples to 'span' and 'break'
1 parent dce58c1 commit c1d610b

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/Data/Text.hs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1359,13 +1359,19 @@ splitAt n t@(Text arr off len)
13591359
-- a pair whose first element is the longest prefix (possibly empty)
13601360
-- of @t@ of elements that satisfy @p@, and whose second is the
13611361
-- remainder of the list.
1362+
--
1363+
-- >>> T.span (=='0') "000AB"
1364+
-- ("000","AB")
13621365
span :: (Char -> Bool) -> Text -> (Text, Text)
13631366
span p t = case span_ p t of
13641367
(# hd,tl #) -> (hd,tl)
13651368
{-# INLINE span #-}
13661369

13671370
-- | /O(n)/ 'break' is like 'span', but the prefix returned is
13681371
-- over elements that fail the predicate @p@.
1372+
--
1373+
-- >>> T.break (=='c') "180cm"
1374+
-- ("180","cm")
13691375
break :: (Char -> Bool) -> Text -> (Text, Text)
13701376
break p = span (not . p)
13711377
{-# INLINE break #-}

src/Data/Text/Lazy.hs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,11 @@ import Text.Printf (PrintfArg, formatArg, formatString)
307307
-- measure. For details, see
308308
-- <http://unicode.org/reports/tr36/#Deletion_of_Noncharacters Unicode Technical Report 36, §3.5 >.)
309309

310+
-- $setup
311+
-- >>> import Data.Text
312+
-- >>> import qualified Data.Text as T
313+
-- >>> :seti -XOverloadedStrings
314+
310315
equal :: Text -> Text -> Bool
311316
equal Empty Empty = True
312317
equal Empty _ = False
@@ -1385,6 +1390,9 @@ breakOnAll pat src
13851390

13861391
-- | /O(n)/ 'break' is like 'span', but the prefix returned is over
13871392
-- elements that fail the predicate @p@.
1393+
--
1394+
-- >>> T.break (=='c') "180cm"
1395+
-- ("180","cm")
13881396
break :: (Char -> Bool) -> Text -> (Text, Text)
13891397
break p t0 = break' t0
13901398
where break' Empty = (empty, empty)
@@ -1400,6 +1408,9 @@ break p t0 = break' t0
14001408
-- a pair whose first element is the longest prefix (possibly empty)
14011409
-- of @t@ of elements that satisfy @p@, and whose second is the
14021410
-- remainder of the list.
1411+
--
1412+
-- >>> T.span (=='0') "000AB"
1413+
-- ("000","AB")
14031414
span :: (Char -> Bool) -> Text -> (Text, Text)
14041415
span p = break (not . p)
14051416
{-# INLINE span #-}

0 commit comments

Comments
 (0)