( self: DocStream.DocStream<A>, f: (a: A) => Option.Option<B>, stack: List.List<AnnotationRemoval> )
| 234 | >(2, (self, f) => Effect.runSync(alterAnnotationSafe(self, f, List.nil()))) |
| 235 | |
| 236 | const alterAnnotationSafe = <A, B>( |
| 237 | self: DocStream.DocStream<A>, |
| 238 | f: (a: A) => Option.Option<B>, |
| 239 | stack: List.List<AnnotationRemoval> |
| 240 | ): Effect.Effect<DocStream.DocStream<B>> => { |
| 241 | switch (self._tag) { |
| 242 | case "CharStream": { |
| 243 | return Effect.map( |
| 244 | Effect.suspend(() => alterAnnotationSafe(self.stream, f, stack)), |
| 245 | char(self.char) |
| 246 | ) |
| 247 | } |
| 248 | case "TextStream": { |
| 249 | return Effect.map( |
| 250 | Effect.suspend(() => alterAnnotationSafe(self.stream, f, stack)), |
| 251 | text(self.text) |
| 252 | ) |
| 253 | } |
| 254 | case "LineStream": { |
| 255 | return Effect.map( |
| 256 | Effect.suspend(() => alterAnnotationSafe(self.stream, f, stack)), |
| 257 | line(self.indentation) |
| 258 | ) |
| 259 | } |
| 260 | case "PushAnnotationStream": { |
| 261 | const altered = f(self.annotation) |
| 262 | if (Option.isSome(altered)) { |
| 263 | return Effect.map( |
| 264 | Effect.suspend(() => alterAnnotationSafe(self.stream, f, List.prepend(stack, DontRemove))), |
| 265 | pushAnnotation(altered.value) |
| 266 | ) |
| 267 | } |
| 268 | return Effect.suspend(() => alterAnnotationSafe(self.stream, f, List.prepend(stack, Remove))) |
| 269 | } |
| 270 | case "PopAnnotationStream": { |
| 271 | if (List.isNil(stack)) { |
| 272 | return Effect.dieMessage( |
| 273 | "BUG: DocStream.alterAnnotations - received empty stack to pop from" + |
| 274 | " - please report an issue at https://github.com/Effect-TS/printer/issues" |
| 275 | ) |
| 276 | } |
| 277 | if (stack.head === DontRemove) { |
| 278 | return Effect.map( |
| 279 | Effect.suspend(() => alterAnnotationSafe(self.stream, f, stack.tail)), |
| 280 | popAnnotation |
| 281 | ) |
| 282 | } |
| 283 | return Effect.suspend(() => alterAnnotationSafe(self.stream, f, stack.tail)) |
| 284 | } |
| 285 | default: { |
| 286 | return Effect.succeed(self as unknown as DocStream.DocStream<B>) |
| 287 | } |
| 288 | } |
| 289 | } |
| 290 | |
| 291 | /** @internal */ |
| 292 | export const reAnnotate = dual< |
no test coverage detected