Skip to content

Commit b0b0278

Browse files
committed
Move concat to constructor functions
1 parent 09edc09 commit b0b0278

3 files changed

Lines changed: 30 additions & 32 deletions

File tree

README.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -67,20 +67,6 @@ Parameters:
6767
`colwidth`
6868
: Maximum number of characters per line
6969

70-
#### concat
71-
72-
`concat (docs[, sep])`
73-
74-
Concatenate the given `Doc`s, interspersing `sep` if specified.
75-
76-
Parameters:
77-
78-
`docs`
79-
: List of `Doc`s
80-
81-
`sep`
82-
: Separator `Doc`
83-
8470
### Doc construction
8571

8672
All functions return a fresh `Doc` element.
@@ -148,6 +134,20 @@ Parameters:
148134

149135
Chomps trailing blank space off of a `Doc`.
150136

137+
#### concat
138+
139+
`concat (docs[, sep])`
140+
141+
Concatenate the given `Doc`s, interspersing `sep` if specified.
142+
143+
Parameters:
144+
145+
`docs`
146+
: List of `Doc`s
147+
148+
`sep`
149+
: Separator `Doc`
150+
151151
#### cr
152152

153153
A carriage return. Does nothing if we're at the beginning of a

src/Foreign/Lua/Module/DocLayout.hs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ module Foreign.Lua.Module.DocLayout (
2929
, brackets
3030
, cblock
3131
, chomp
32+
, concat
3233
, cr
3334
, double_quotes
3435
, empty
@@ -49,7 +50,6 @@ module Foreign.Lua.Module.DocLayout (
4950

5051
-- * Functions
5152
, render
52-
, concat
5353

5454
-- * Marshaling
5555
, peekDoc
@@ -94,6 +94,7 @@ pushModule = do
9494
Lua.addfunction "brackets" brackets
9595
Lua.addfunction "cblock" cblock
9696
Lua.addfunction "chomp" chomp
97+
Lua.addfunction "concat" concat
9798
Lua.addfunction "double_quotes" double_quotes
9899
Lua.addfunction "flush" flush
99100
Lua.addfunction "hang" hang
@@ -108,8 +109,7 @@ pushModule = do
108109
Lua.addfunction "prefixed" prefixed
109110
Lua.addfunction "rblock" rblock
110111
Lua.addfunction "vfill" vfill
111-
-- renderign
112-
Lua.addfunction "concat" concat
112+
-- rendering
113113
Lua.addfunction "render" render
114114
return 1
115115

@@ -124,13 +124,6 @@ preloadModule = flip Lua.preloadhs pushModule
124124
render :: Doc Text -> Optional Int -> Lua Text
125125
render doc optLength = return $ Doc.render (Lua.fromOptional optLength) doc
126126

127-
-- | Concatenates a list of @'Doc'@s.
128-
concat :: [Doc Text] -> Optional (Doc Text) -> Lua (Doc Text)
129-
concat docs optSep = return $
130-
case Lua.fromOptional optSep of
131-
Nothing -> mconcat docs
132-
Just sep -> mconcat $ intersperse sep docs
133-
134127
--
135128
-- Constructors
136129
--
@@ -169,6 +162,13 @@ cblock width = return . Doc.cblock width
169162
chomp :: Doc Text -> Lua (Doc Text)
170163
chomp = return . Doc.chomp
171164

165+
-- | Concatenates a list of @'Doc'@s.
166+
concat :: [Doc Text] -> Optional (Doc Text) -> Lua (Doc Text)
167+
concat docs optSep = return $
168+
case Lua.fromOptional optSep of
169+
Nothing -> mconcat docs
170+
Just sep -> mconcat $ intersperse sep docs
171+
172172
-- | A carriage return. Does nothing if we're at the beginning of
173173
-- a line; otherwise inserts a newline.
174174
cr :: Doc Text

test/test-doclayout.lua

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,6 @@ return {
2323
test('space', function ()
2424
assert.are_equal(type(doclayout.space), 'userdata')
2525
end),
26-
},
27-
28-
group 'functions' {
29-
group 'render' {
30-
test('empty doc', function ()
31-
assert.are_equal(doclayout.render(doclayout.empty), '')
32-
end)
33-
},
3426

3527
group 'concat' {
3628
test('without sep', function ()
@@ -55,6 +47,12 @@ return {
5547
}
5648
},
5749

50+
group 'render' {
51+
test('empty doc', function ()
52+
assert.are_equal(doclayout.render(doclayout.empty), '')
53+
end)
54+
},
55+
5856
group 'Doc type' {
5957
test('empty strings equal the empty Doc', function ()
6058
assert.are_equal(doclayout.empty .. '', doclayout.empty)

0 commit comments

Comments
 (0)