Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Glasgow Haskell Compiler
GHC
Commits
797df55a
Commit
797df55a
authored
Jan 15, 2015
by
Andrey Mokhov
Browse files
Add chunksOfSize helper function.
parent
f80948c6
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/Util.hs
View file @
797df55a
module
Util
(
module
Data
.
Char
,
replaceIf
,
replaceEq
,
replaceSeparators
replaceIf
,
replaceEq
,
replaceSeparators
,
chunksOfSize
)
where
import
Base
import
Data.Char
replaceIf
::
(
a
->
Bool
)
->
a
->
[
a
]
->
[
a
]
replaceIf
p
to
=
map
(
\
from
->
if
p
from
then
to
else
from
)
replaceIf
p
to
=
map
(
\
from
->
if
p
from
then
to
else
from
)
replaceEq
::
Eq
a
=>
a
->
a
->
[
a
]
->
[
a
]
replaceEq
from
=
replaceIf
(
==
from
)
...
...
@@ -15,3 +16,17 @@ replaceEq from = replaceIf (== from)
replaceSeparators
::
Char
->
String
->
String
replaceSeparators
=
replaceIf
isPathSeparator
-- (chunksOfSize size ss) splits a list of strings 'ss' into chunks not
-- exceeding the given 'size'.
chunksOfSize
::
Int
->
[
String
]
->
[[
String
]]
chunksOfSize
_
[]
=
[]
chunksOfSize
size
ss
=
reverse
chunk
:
chunksOfSize
size
rest
where
(
chunk
,
rest
)
=
go
[]
0
ss
go
chunk
_
[]
=
(
chunk
,
[]
)
go
chunk
chunkSize
(
s
:
ss
)
=
let
newSize
=
chunkSize
+
length
s
(
newChunk
,
rest
)
=
go
(
s
:
chunk
)
newSize
ss
in
if
newSize
>
size
then
(
chunk
,
s
:
ss
)
else
(
newChunk
,
rest
)
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment