Add ./Prelude/Text/concatMap (#73)

This commit is contained in:
Gabriel Gonzalez 2017-06-17 09:05:48 -07:00 committed by GitHub
parent 000fb8ebc4
commit 2b8b89e41a
2 changed files with 48 additions and 10 deletions

20
Prelude/Text/concatMap Normal file
View File

@ -0,0 +1,20 @@
{-
Transform each value in a `List` into `Text` and concatenate the result
Examples:
```
./concatMap Integer (λ(n : Integer) → "${Integer/show n} ") [0, 1, 2]
= "0 1 2 "
./concatMap Integer (λ(n : Integer) → "${Integer/show n} ") ([] : List Integer)
= ""
```
-}
let concatMap : ∀(a : Type) → (a → Text) → List a → Text
= λ(a : Type)
→ λ(f : a → Text)
→ λ(xs : List a)
→ List/fold a xs Text (λ(x : a) → λ(y : Text) → f x ++ y) ""
in concatMap

View File

@ -236,14 +236,18 @@ exampleTests =
[ _Text_concat_0
, _Text_concat_1
]
, Test.Tasty.testGroup "concatSep"
[ _Text_concatSep_0
, _Text_concatSep_1
, Test.Tasty.testGroup "concatMap"
[ _Text_concatMap_0
, _Text_concatMap_1
]
, Test.Tasty.testGroup "concatMapSep"
[ _Text_concatMapSep_0
, _Text_concatMapSep_1
]
, Test.Tasty.testGroup "concatSep"
[ _Text_concatSep_0
, _Text_concatSep_1
]
]
]
@ -1143,17 +1147,17 @@ _Text_concat_1 = Test.Tasty.HUnit.testCase "Example #1" (do
|]
Util.assertNormalizesTo e "\"\"" )
_Text_concatSep_0 :: TestTree
_Text_concatSep_0 = Test.Tasty.HUnit.testCase "Example #0" (do
_Text_concatMap_0 :: TestTree
_Text_concatMap_0 = Test.Tasty.HUnit.testCase "Example #0" (do
e <- Util.code [NeatInterpolation.text|
./Prelude/Text/concatSep ", " ["ABC", "DEF", "GHI"]
./Prelude/Text//concatMap Integer (λ(n : Integer) "${Integer/show n} ") [0, 1, 2]
|]
Util.assertNormalizesTo e "\"ABC, DEF, GHI\"" )
Util.assertNormalizesTo e "\"0 1 2 \"" )
_Text_concatSep_1 :: TestTree
_Text_concatSep_1 = Test.Tasty.HUnit.testCase "Example #1" (do
_Text_concatMap_1 :: TestTree
_Text_concatMap_1 = Test.Tasty.HUnit.testCase "Example #1" (do
e <- Util.code [NeatInterpolation.text|
./Prelude/Text/concatSep ", " ([] : List Text)
./Prelude/Text/concatMap Integer (λ(n : Integer) "${Integer/show n} ") ([] : List Integer)
|]
Util.assertNormalizesTo e "\"\"" )
@ -1170,3 +1174,17 @@ _Text_concatMapSep_1 = Test.Tasty.HUnit.testCase "Example #1" (do
./Prelude/Text/concatMapSep ", " Integer Integer/show ([] : List Integer)
|]
Util.assertNormalizesTo e "\"\"" )
_Text_concatSep_0 :: TestTree
_Text_concatSep_0 = Test.Tasty.HUnit.testCase "Example #0" (do
e <- Util.code [NeatInterpolation.text|
./Prelude/Text/concatSep ", " ["ABC", "DEF", "GHI"]
|]
Util.assertNormalizesTo e "\"ABC, DEF, GHI\"" )
_Text_concatSep_1 :: TestTree
_Text_concatSep_1 = Test.Tasty.HUnit.testCase "Example #1" (do
e <- Util.code [NeatInterpolation.text|
./Prelude/Text/concatSep ", " ([] : List Text)
|]
Util.assertNormalizesTo e "\"\"" )