MCPcopy
hub / github.com/Effect-TS/effect / alterAnnotationSafe

Function alterAnnotationSafe

packages/printer/src/internal/docStream.ts:236–289  ·  view source on GitHub ↗
(
  self: DocStream.DocStream<A>,
  f: (a: A) => Option.Option<B>,
  stack: List.List<AnnotationRemoval>
)

Source from the content-addressed store, hash-verified

234>(2, (self, f) => Effect.runSync(alterAnnotationSafe(self, f, List.nil())))
235
236const 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 */
292export const reAnnotate = dual<

Callers 1

docStream.tsFile · 0.85

Calls 7

pushAnnotationFunction · 0.85
charFunction · 0.70
textFunction · 0.70
lineFunction · 0.70
mapMethod · 0.65
dieMessageMethod · 0.65
fFunction · 0.50

Tested by

no test coverage detected