From 42d5bc2de2e4695d923444312d2498405d27d5ef Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Thu, 15 Sep 2022 12:27:23 -0700 Subject: [PATCH] Extract helper. --- codegen/Elm/Extra.elm | 30 ++++++++++++++++++++++++++++++ codegen/Generate.elm | 27 +-------------------------- 2 files changed, 31 insertions(+), 26 deletions(-) create mode 100644 codegen/Elm/Extra.elm diff --git a/codegen/Elm/Extra.elm b/codegen/Elm/Extra.elm new file mode 100644 index 00000000..a5f95738 --- /dev/null +++ b/codegen/Elm/Extra.elm @@ -0,0 +1,30 @@ +module Elm.Extra exposing (topLevelValue) + +import Elm +import Elm.Declare + + +topLevelValue : + String + -> Elm.Expression + -> + { declaration : Elm.Declaration + , reference : Elm.Expression + , referenceFrom : List String -> Elm.Expression + } +topLevelValue name expression = + let + declaration_ : + { declaration : Elm.Declaration + , call : List Elm.Expression -> Elm.Expression + , callFrom : List String -> List Elm.Expression -> Elm.Expression + } + declaration_ = + Elm.Declare.function name + [] + (\_ -> expression) + in + { declaration = declaration_.declaration + , reference = declaration_.call [] + , referenceFrom = \from -> declaration_.callFrom from [] + } diff --git a/codegen/Generate.elm b/codegen/Generate.elm index 9dd65741..b74c752e 100644 --- a/codegen/Generate.elm +++ b/codegen/Generate.elm @@ -7,6 +7,7 @@ import Elm.Annotation import Elm.Case import Elm.CodeGen import Elm.Declare +import Elm.Extra exposing (topLevelValue) import Elm.Op import Elm.Pretty import Gen.Basics @@ -366,32 +367,6 @@ routeToPath routes = ) -topLevelValue : - String - -> Elm.Expression - -> - { declaration : Elm.Declaration - , reference : Elm.Expression - , referenceFrom : List String -> Elm.Expression - } -topLevelValue name expression = - let - declaration_ : - { declaration : Elm.Declaration - , call : List Elm.Expression -> Elm.Expression - , callFrom : List String -> List Elm.Expression -> Elm.Expression - } - declaration_ = - Elm.Declare.function name - [] - (\_ -> expression) - in - { declaration = declaration_.declaration - , reference = declaration_.call [] - , referenceFrom = \from -> declaration_.callFrom from [] - } - - expose : Elm.Declaration -> Elm.Declaration expose declaration = declaration