git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Extract functions for rendering constraints
61cfbafHarry Garrood
src/Language/PureScript/Docs/Render.hs+21−13
@@ -75,18 +75,8 @@ renderChildDeclarationWithOptions opts ChildDeclaration{..} =
75 [ keywordInstance
75 [ keywordInstance
76 , ident cdeclTitle
76 , ident cdeclTitle
77 , syntax "::"
77 , syntax "::"
78− ] ++ maybe [] (:[]) constraints'
78+ ] ++ maybe [] (:[]) (renderConstraints constraints)
79 ++ [ renderType' ty ]
79 ++ [ renderType' ty ]
80− where
81− constraints'
82− | null constraints = Nothing
83− | otherwise = Just $
84− syntax "("
85− <> renderedConstraints
86− <> syntax ")" <> sp <> syntax "=>"
87−
88− renderedConstraints = mintersperse (syntax "," <> sp)
89− (map renderConstraint constraints)
90 ChildDataConstructor args ->
80 ChildDataConstructor args ->
91 [ renderType' typeApp' ]
81 [ renderType' typeApp' ]
92 where
82 where
@@ -102,8 +92,26 @@ renderChildDeclarationWithOptions opts ChildDeclaration{..} =
102 renderType' = renderTypeWithOptions opts
92 renderType' = renderTypeWithOptions opts
103
93
104renderConstraint :: (P.Qualified P.ProperName, [P.Type]) -> RenderedCode
94renderConstraint :: (P.Qualified P.ProperName, [P.Type]) -> RenderedCode
105−renderConstraint (pn, tys) =
95+renderConstraint = renderConstraintWithOptions defaultRenderTypeOptions
96+
97+renderConstraintWithOptions :: RenderTypeOptions -> (P.Qualified P.ProperName, [P.Type]) -> RenderedCode
98+renderConstraintWithOptions opts (pn, tys) =
106− renderType $ foldl P.TypeApp (P.TypeConstructor pn) tys
99+ renderTypeWithOptions opts $ foldl P.TypeApp (P.TypeConstructor pn) tys
100+
101+renderConstraints :: [P.Constraint] -> Maybe RenderedCode
102+renderConstraints = renderConstraintsWithOptions defaultRenderTypeOptions
103+
104+renderConstraintsWithOptions :: RenderTypeOptions -> [P.Constraint] -> Maybe RenderedCode
105+renderConstraintsWithOptions opts constraints
106+ | null constraints = Nothing
107+ | otherwise = Just $
108+ syntax "("
109+ <> renderedConstraints
110+ <> syntax ")" <> sp <> syntax "=>"
111+ where
112+ renderedConstraints =
113+ mintersperse (syntax "," <> sp)
114+ (map (renderConstraintWithOptions opts) constraints)
107
115
108notQualified :: String -> P.Qualified P.ProperName
116notQualified :: String -> P.Qualified P.ProperName
109notQualified = P.Qualified Nothing . P.ProperName
117notQualified = P.Qualified Nothing . P.ProperName