MCPcopy Create free account
hub / github.com/Effect-TS/effect / sanitizeSafe

Function sanitizeSafe

packages/printer/src/internal/doc.ts:856–908  ·  view source on GitHub ↗
(self: Doc.Doc<A>)

Source from the content-addressed store, hash-verified

854export const sanitize = <A>(self: Doc.Doc<A>): Doc.Doc<A> => Effect.runSync(sanitizeSafe(self))
855
856const sanitizeSafe = <A>(self: Doc.Doc<A>): Effect.Effect<Doc.Doc<A>> => {
857 switch (self._tag) {
858 case "Char":
859 case "Text": {
860 return Effect.succeed(sanitizeLeaf(self))
861 }
862 case "Cat": {
863 return Effect.zipWith(
864 Effect.suspend(() => sanitizeSafe(self.left)),
865 sanitizeSafe(self.right),
866 (left, right) => cat(left, right)
867 )
868 }
869 case "FlatAlt": {
870 return Effect.zipWith(
871 Effect.suspend(() => sanitizeSafe(self.left)),
872 sanitizeSafe(self.right),
873 (left, right) => flatAlt(left, right)
874 )
875 }
876 case "Union": {
877 return Effect.zipWith(
878 Effect.suspend(() => sanitizeSafe(self.left)),
879 sanitizeSafe(self.right),
880 (left, right) => union(left, right)
881 )
882 }
883 case "Nest": {
884 return Effect.map(
885 Effect.suspend(() => sanitizeSafe(self.doc)),
886 nest(self.indent)
887 )
888 }
889 case "Column": {
890 return Effect.succeed(column((position) => Effect.runSync(sanitizeSafe(self.react(position)))))
891 }
892 case "WithPageWidth": {
893 return Effect.succeed(pageWidth((width) => Effect.runSync(sanitizeSafe(self.react(width)))))
894 }
895 case "Nesting": {
896 return Effect.succeed(nesting((level) => Effect.runSync(sanitizeSafe(self.react(level)))))
897 }
898 case "Annotated": {
899 return Effect.map(
900 Effect.suspend(() => sanitizeSafe(self.doc)),
901 (doc) => annotate(doc, self.annotation)
902 )
903 }
904 default: {
905 return Effect.succeed(self)
906 }
907 }
908}
909
910/** @internal */
911export const surround = dual<

Callers 1

sanitizeFunction · 0.85

Calls 6

sanitizeLeafFunction · 0.85
columnFunction · 0.85
pageWidthFunction · 0.85
nestingFunction · 0.85
mapMethod · 0.65
annotateFunction · 0.50

Tested by

no test coverage detected