Skip to content

Instantly share code, notes, and snippets.

@Janiczek
Created October 28, 2021 20:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Janiczek/eefe1677354e2ac6397a6332ac116196 to your computer and use it in GitHub Desktop.
Save Janiczek/eefe1677354e2ac6397a6332ac116196 to your computer and use it in GitHub Desktop.
-- The answer is always traverse
-- https://impurepics.com/posts/2020-10-03-always-traverse.html
Task.maybe : (a -> Task x b) -> Maybe a -> Task x (Maybe b)
Task.maybe toTask maybe =
case maybe of
Nothing ->
Task.succeed Nothing
Just input ->
toTask input
enrichWithThemes : { inherited : Bool } -> Branding -> Task x ( Branding, Theme )
enrichWithThemes { inherited } branding =
UserGroupBranding.getBrandingThemesTask { userGroupId = params.userGroupId, inherited = inherited }
|> Task.map (\themes -> ( branding, themes ))
enrichBranding : Inheritance Branding -> Task Http.Error (Inheritance ( Branding, Themes ))
enrichBranding intermediate =
Task.map2
(\branding parentBranding ->
{ ownValue = branding
, inheritableValue = parentBranding
, isInherited = intermediate.isInherited
}
)
(intermediate.ownValue
|> Task.maybe (enrichWithThemes { inherited = False })
)
(intermediate.inheritableValue
|> Task.maybe (enrichWithThemes { inherited = True })
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment