0 | module Data.String.Builder
2 | import Control.Relation
4 | import public Data.DiffList
5 | import Syntax.PreorderReasoning.Generic
9 | Builder = DiffList String
11 | public export %inline
12 | FromString Builder where
13 | fromString = singleton
16 | char : Char -> Builder
17 | char = singleton . cast
19 | public export %inline
20 | build : Builder -> String
21 | build b = concat $
DiffList.toList b
24 | sepBy : Builder -> List Builder -> Builder
25 | sepBy _ [] = neutral
27 | sepBy sep (x :: xs) = MkDiffList
28 | (\rest => x.append (go xs rest))
30 | let xsPrf = goIsSuffix _ _
32 | in transitive xsPrf xPrf)
34 | go : List Builder -> List String -> List String
36 | go (x :: xs) acc = sep.append (x.append (go xs acc))
39 | goIsSuffix : (xs : List Builder) -> (rest : List String) -> IsSuffixOf rest (go xs rest)
40 | goIsSuffix [] rest = SuffixRefl
41 | goIsSuffix (x :: xs) rest = CalcWith $
43 | <~ go xs rest ...(goIsSuffix _ _)
44 | <~ x.append (go xs rest) ...(x.isSuffix _)
45 | <~ sep.append (x.append (go xs rest)) ...(sep.isSuffix _)
46 | <~ go (x :: xs) rest ...(reflexive)
48 | public export %inline
49 | showB : Show a => a -> Builder
50 | showB = singleton . show