Skip to content

Commit 0a8c498

Browse files
committed
added templateS
1 parent 9c08592 commit 0a8c498

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,6 @@ Sample usage:
1919
> import Data.Show (show)
2020
> "Pi: ${pi}, Phi: ${phi}" <^> ["pi" /\ (show 3.1415), "phi" /\ (show 1.618)]
2121
"Pi: 3.1415, Phi: 1.618"
22+
> "Pi: ${pi}, Phi: ${phi}" <-> ["pi" /\ 3.1415, "phi" /\ 1.618]
23+
"Pi: 3.1415, Phi: 1.618"
2224
```
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,25 @@
11
module Data.TemplateString
22
((<^>)
33
, template
4+
, (<->)
5+
, templateS
46
) where
57

8+
import Prelude (map, ($), (<<<), show)
69
import Data.Function.Uncurried (Fn2, runFn2)
710
import Data.Tuple (Tuple)
11+
import Data.Show (class Show)
812

913
-- | This is the safe version. The user is required to give a String representation of the object
1014
template :: String -> Array (Tuple String String) -> String
1115
template = runFn2 _template
1216

1317
infix 7 template as <^>
1418

19+
-- | This version can use any instance of Show
20+
templateS :: forall a. (Show a) => String -> Array (Tuple String a) -> String
21+
templateS s vs = runFn2 _template s $ (map <<< map) show vs
22+
23+
infix 7 templateS as <->
24+
1525
foreign import _template :: Fn2 String (Array (Tuple String String)) String

0 commit comments

Comments
 (0)