Skip to content

Commit

Permalink
Update bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
miniBill committed Aug 23, 2024
1 parent e3323b1 commit 9e82633
Show file tree
Hide file tree
Showing 13 changed files with 244 additions and 62 deletions.
2 changes: 1 addition & 1 deletion cli/gen-package/codegen/Gen/Array.elm
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ filter filterArg_ filterArg_0 =

annotation_ : { array : Type.Annotation -> Type.Annotation }
annotation_ =
{ array = \arrayArg0 -> Type.namedWith [ "Array" ] "Array" [ arrayArg0 ] }
{ array = \arrayArg_0 -> Type.namedWith [ "Array" ] "Array" [ arrayArg_0 ] }


call_ :
Expand Down
4 changes: 2 additions & 2 deletions cli/gen-package/codegen/Gen/Dict.elm
Original file line number Diff line number Diff line change
Expand Up @@ -893,8 +893,8 @@ merge mergeArg_ mergeArg_0 mergeArg_1 mergeArg_2 mergeArg_3 mergeArg_4 =
annotation_ : { dict : Type.Annotation -> Type.Annotation -> Type.Annotation }
annotation_ =
{ dict =
\dictArg0 dictArg1 ->
Type.namedWith [ "Dict" ] "Dict" [ dictArg0, dictArg1 ]
\dictArg_0 dictArg_1 ->
Type.namedWith [ "Dict" ] "Dict" [ dictArg_0, dictArg_1 ]
}


Expand Down
19 changes: 10 additions & 9 deletions cli/gen-package/codegen/Gen/Elm.elm
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,10 @@ withDocumentation withDocumentationArg_ withDocumentationArg_0 =
[ Elm.string withDocumentationArg_, withDocumentationArg_0 ]


{-| group: { title : String, docs : String } -> List Elm.Declaration -> Elm.Declaration -}
{-| Group declarations under a title together in the doc comment at the top of the generated module.
group: { title : String, docs : String } -> List Elm.Declaration -> Elm.Declaration
-}
group :
{ title : String, docs : String } -> List Elm.Expression -> Elm.Expression
group groupArg_ groupArg_0 =
Expand Down Expand Up @@ -680,7 +683,7 @@ exposeConstructor exposeConstructorArg_ =
Pass in a function that determines how to render a `@docs` comment.
Each exposed item is grouped based on the string used in [exposeWith](#exposeWith).
Each exposed item is grouped using [group](#group).
**aliases** allow you to specify a module alias to be used.
Expand Down Expand Up @@ -938,12 +941,10 @@ Results in
**Note** — Elm CodeGen will protect variable names if they're used in a nested `fn*` by adding a string of numbers to the end of the name. So, you may see a variable name be something like `myVariable_0_1`.
If you absolutely don't want this behavior, you'll need to use [`functionAdvanced`](#functionAdvanced).
fn: Elm.Arg.Arg arg -> (arg -> Elm.Expression) -> Elm.Expression
-}
fn : Elm.Expression -> (Elm.Expression -> Elm.Expression) -> Elm.Expression
fn fnArg_ fnArg_0 =
fn fn_Arg fn_Arg0 =
Elm.apply
(Elm.value
{ importFrom = [ "Elm" ]
Expand All @@ -963,7 +964,7 @@ fn fnArg_ fnArg_0 =
)
}
)
[ fnArg_, Elm.functionReduced "fnUnpack" fnArg_0 ]
[ fn_Arg, Elm.functionReduced "fnUnpack" fn_Arg0 ]


{-| fn2:
Expand Down Expand Up @@ -1701,7 +1702,7 @@ annotation_ =
"Declaration"
[]
(Type.namedWith [ "Internal", "Compiler" ] "Declaration" [])
, fn = \fnArg0 -> Type.namedWith [ "Elm" ] "Fn" [ fnArg0 ]
, fn = \fnArg_0 -> Type.namedWith [ "Elm" ] "Fn" [ fnArg_0 ]
, variant = Type.namedWith [ "Elm" ] "Variant" []
}

Expand Down Expand Up @@ -2377,7 +2378,7 @@ call_ =
)
[ bodyArg_, bodyArg_0 ]
, fn =
\fnArg_ fnArg_0 ->
\fn_Arg fn_Arg0 ->
Elm.apply
(Elm.value
{ importFrom = [ "Elm" ]
Expand All @@ -2397,7 +2398,7 @@ call_ =
)
}
)
[ fnArg_, fnArg_0 ]
[ fn_Arg, fn_Arg0 ]
, fn2 =
\fn2Arg_ fn2Arg_0 fn2Arg_1 ->
Elm.apply
Expand Down
196 changes: 184 additions & 12 deletions cli/gen-package/codegen/Gen/Elm/Arg.elm
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module Gen.Elm.Arg exposing
, field
, ignore
, item
, items
, list
, listRemaining
, moduleName_
Expand All @@ -21,7 +22,7 @@ module Gen.Elm.Arg exposing
)

{-|
@docs moduleName_, unit, var, varWith, tuple, triple, record, field, aliasAs, ignore, string, char, list, item, listRemaining, customType, annotation_, call_, values_
@docs moduleName_, unit, var, varWith, tuple, triple, record, field, aliasAs, ignore, string, char, list, item, items, listRemaining, customType, annotation_, call_, values_
-}


Expand All @@ -35,7 +36,10 @@ moduleName_ =
[ "Elm", "Arg" ]


{-| unit: Elm.Arg.Arg Elm.Arg.Expression -}
{-| An empty tuple `()` is generally called "unit".
unit: Elm.Arg.Arg Elm.Arg.Expression
-}
unit : Elm.Expression
unit =
Elm.value
Expand Down Expand Up @@ -175,7 +179,31 @@ triple tripleArg_ tripleArg_0 tripleArg_1 =
[ tripleArg_, tripleArg_0, tripleArg_1 ]


{-| record: fields -> Elm.Arg.Arg fields -}
{-| Unpack record fields.
let
args =
Elm.Arg.record
|> Elm.Arg.field "first" (Arg.var "first")
|> Elm.Arg.field "second" (Arg.var "second")
in
Elm.fn args
(\{ first, second } ->
Elm.record
[ ( "first", first )
, ( "second", second )
]
)
Would generate
\{ first, second } ->
{ first = first
, second = second
}
record: fields -> Elm.Arg.Arg fields
-}
record : Elm.Expression -> Elm.Expression
record recordArg_ =
Elm.apply
Expand Down Expand Up @@ -231,7 +259,34 @@ field fieldArg_ fieldArg_0 =
[ Elm.string fieldArg_, fieldArg_0 ]


{-| aliasAs: String -> Elm.Arg.Arg arg -> Elm.Arg.Arg ( arg, Elm.Arg.Expression ) -}
{-| Unpack a pattern, but keep a reference to the original value.
let
args =
Elm.Arg.customType "MyCustomType" Tuple.pair
|> Elm.Arg.item (Arg.var "first")
|> Elm.Arg.item (Arg.var "second")
|> Elm.Arg.aliasAs "myAlias"
in
Elm.fn args
(\( ( first, second ), myAlias ) ->
Elm.record
[ ( "first", first )
, ( "second", second )
, ( "myAlias", myAlias )
]
)
Will generate
\((MyCustomType first second) as myAlias) ->
{ first = first
, second = second
, myAlias = myAlias
}
aliasAs: String -> Elm.Arg.Arg arg -> Elm.Arg.Arg ( arg, Elm.Arg.Expression )
-}
aliasAs : String -> Elm.Expression -> Elm.Expression
aliasAs aliasAsArg_ aliasAsArg_0 =
Elm.apply
Expand Down Expand Up @@ -265,7 +320,10 @@ aliasAs aliasAsArg_ aliasAsArg_0 =
[ Elm.string aliasAsArg_, aliasAsArg_0 ]


{-| ignore: Elm.Arg.Arg Elm.Arg.Expression -}
{-| Will generate `_` to ignore an argument or pattern.
ignore: Elm.Arg.Arg Elm.Arg.Expression
-}
ignore : Elm.Expression
ignore =
Elm.value
Expand Down Expand Up @@ -406,6 +464,41 @@ item itemArg_ itemArg_0 =
[ itemArg_, itemArg_0 ]


{-| items: List (Elm.Arg.Arg arg) -> Elm.Arg.Arg (List arg -> a) -> Elm.Arg.Arg a -}
items : List Elm.Expression -> Elm.Expression -> Elm.Expression
items itemsArg_ itemsArg_0 =
Elm.apply
(Elm.value
{ importFrom = [ "Elm", "Arg" ]
, name = "items"
, annotation =
Just
(Type.function
[ Type.list
(Type.namedWith
[ "Elm", "Arg" ]
"Arg"
[ Type.var "arg" ]
)
, Type.namedWith
[ "Elm", "Arg" ]
"Arg"
[ Type.function
[ Type.list (Type.var "arg") ]
(Type.var "a")
]
]
(Type.namedWith
[ "Elm", "Arg" ]
"Arg"
[ Type.var "a" ]
)
)
}
)
[ Elm.list itemsArg_, itemsArg_0 ]


{-| listRemaining: String -> Elm.Arg.Arg (Elm.Arg.Expression -> a) -> Elm.Arg.Arg a -}
listRemaining : String -> Elm.Expression -> Elm.Expression
listRemaining listRemainingArg_ listRemainingArg_0 =
Expand Down Expand Up @@ -440,13 +533,33 @@ listRemaining listRemainingArg_ listRemainingArg_0 =
[ Elm.string listRemainingArg_, listRemainingArg_0 ]


{-| Arg.customType "MyCustomType" Tuple.pair
|> Arg.item (Arg.var "first")
|> Arg.item (Arg.var "second")
{-| Let's say you have a custom type like
Will generate
type MyCustomType
= MyCustomType String Int
And you want to extract the String and Int
let
args =
Elm.Arg.customType "MyCustomType" Tuple.pair
|> Elm.Arg.item (Arg.var "first")
|> Elm.Arg.item (Arg.var "second")
in
Elm.fn args
(\( first, second ) ->
Elm.record
[ ( "first", first )
, ( "second", second )
]
)
Which will generate
MyCustomType first second
\(MyCustomType first second) ->
{ first = first
, second = second
}
customType: String -> a -> Elm.Arg.Arg a
-}
Expand Down Expand Up @@ -474,11 +587,11 @@ customType customTypeArg_ customTypeArg_0 =
annotation_ : { arg : Type.Annotation -> Type.Annotation }
annotation_ =
{ arg =
\argArg0 ->
\argArg_0 ->
Type.alias
moduleName_
"Arg"
[ argArg0 ]
[ argArg_0 ]
(Type.namedWith [ "Internal", "Arg" ] "Arg" [ Type.var "val" ])
}

Expand All @@ -496,6 +609,7 @@ call_ :
, char : Elm.Expression -> Elm.Expression
, list : Elm.Expression -> Elm.Expression
, item : Elm.Expression -> Elm.Expression -> Elm.Expression
, items : Elm.Expression -> Elm.Expression -> Elm.Expression
, listRemaining : Elm.Expression -> Elm.Expression -> Elm.Expression
, customType : Elm.Expression -> Elm.Expression -> Elm.Expression
}
Expand Down Expand Up @@ -792,6 +906,38 @@ call_ =
}
)
[ itemArg_, itemArg_0 ]
, items =
\itemsArg_ itemsArg_0 ->
Elm.apply
(Elm.value
{ importFrom = [ "Elm", "Arg" ]
, name = "items"
, annotation =
Just
(Type.function
[ Type.list
(Type.namedWith
[ "Elm", "Arg" ]
"Arg"
[ Type.var "arg" ]
)
, Type.namedWith
[ "Elm", "Arg" ]
"Arg"
[ Type.function
[ Type.list (Type.var "arg") ]
(Type.var "a")
]
]
(Type.namedWith
[ "Elm", "Arg" ]
"Arg"
[ Type.var "a" ]
)
)
}
)
[ itemsArg_, itemsArg_0 ]
, listRemaining =
\listRemainingArg_ listRemainingArg_0 ->
Elm.apply
Expand Down Expand Up @@ -859,6 +1005,7 @@ values_ :
, char : Elm.Expression
, list : Elm.Expression
, item : Elm.Expression
, items : Elm.Expression
, listRemaining : Elm.Expression
, customType : Elm.Expression
}
Expand Down Expand Up @@ -1108,6 +1255,31 @@ values_ =
)
)
}
, items =
Elm.value
{ importFrom = [ "Elm", "Arg" ]
, name = "items"
, annotation =
Just
(Type.function
[ Type.list
(Type.namedWith
[ "Elm", "Arg" ]
"Arg"
[ Type.var "arg" ]
)
, Type.namedWith
[ "Elm", "Arg" ]
"Arg"
[ Type.function
[ Type.list (Type.var "arg") ]
(Type.var "a")
]
]
(Type.namedWith [ "Elm", "Arg" ] "Arg" [ Type.var "a" ]
)
)
}
, listRemaining =
Elm.value
{ importFrom = [ "Elm", "Arg" ]
Expand Down
Loading

0 comments on commit 9e82633

Please sign in to comment.