( self: DocTree.DocTree<A>, M: monoid.Monoid<M>, f: (a: A) => M )
| 237 | >(3, (self, M, f) => Effect.runSync(foldMapSafe(self, M, f))) |
| 238 | |
| 239 | const foldMapSafe = <A, M>( |
| 240 | self: DocTree.DocTree<A>, |
| 241 | M: monoid.Monoid<M>, |
| 242 | f: (a: A) => M |
| 243 | ): Effect.Effect<M> => { |
| 244 | switch (self._tag) { |
| 245 | case "EmptyTree": |
| 246 | case "CharTree": |
| 247 | case "TextTree": |
| 248 | case "LineTree": { |
| 249 | return Effect.succeed(M.empty) |
| 250 | } |
| 251 | case "AnnotationTree": { |
| 252 | return Effect.map( |
| 253 | Effect.suspend(() => foldMapSafe(self.tree, M, f)), |
| 254 | (that) => M.combine(f(self.annotation), that) |
| 255 | ) |
| 256 | } |
| 257 | case "ConcatTree": { |
| 258 | if (Arr.isEmptyReadonlyArray(self.trees)) { |
| 259 | return Effect.succeed(M.empty) |
| 260 | } |
| 261 | return Effect.map( |
| 262 | Effect.forEach(self.trees, (tree) => foldMapSafe(tree, M, f)), |
| 263 | (trees) => { |
| 264 | const head = trees[0] |
| 265 | const tail = trees.slice(1) |
| 266 | return Arr.reduce(tail, head, M.combine) |
| 267 | } |
| 268 | ) |
| 269 | } |
| 270 | } |
| 271 | } |
| 272 | |
| 273 | // ----------------------------------------------------------------------------- |
| 274 | // Rendering |
no test coverage detected
searching dependent graphs…