Skip to content

Commit

Permalink
Merge pull request #100 from miniBill/arg-int
Browse files Browse the repository at this point in the history
Add Arg.int
  • Loading branch information
mdgriffith authored Sep 1, 2024
2 parents 4b88e65 + a0678f0 commit aaf9daf
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 4 deletions.
10 changes: 8 additions & 2 deletions src/Elm/Arg.elm
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module Elm.Arg exposing
, tuple, triple
, record, field
, aliasAs
, ignore, string, char
, ignore, string, char, int
, list, item, items, listRemaining
, customType
)
Expand Down Expand Up @@ -60,7 +60,7 @@ Will generate
## Useful for case expressions
@docs ignore, string, char
@docs ignore, string, char, int
@docs list, item, items, listRemaining
Expand Down Expand Up @@ -183,6 +183,12 @@ char =
Internal.Arg.char


{-| -}
int : Int -> Arg Expression
int =
Internal.Arg.int


{-| Will generate `_` to ignore an argument or pattern.
-}
ignore : Arg Expression
Expand Down
37 changes: 35 additions & 2 deletions src/Internal/Arg.elm
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module Internal.Arg exposing
, aliasAs
, var, varWith
, triple, tuple
, char, string
, char, string, int
, customType
, item, items, list, listRemaining, record, field
, ignore, unit
Expand All @@ -19,7 +19,7 @@ module Internal.Arg exposing
@docs triple, tuple
@docs char, string
@docs char, string, int
@docs customType
Expand Down Expand Up @@ -140,6 +140,39 @@ string str =
)


{-| -}
int : Int -> Arg Expression
int intVal =
Arg
(\index ->
let
annotation =
Ok
{ inferences = Dict.empty
, type_ = Internal.Types.int
, aliases = Compiler.emptyAliases
}

imports =
[]
in
{ details =
{ imports = imports
, pattern = Compiler.nodify (Pattern.IntPattern intVal)
, annotation = annotation
}
, index = Index.next index
, value =
Compiler.Expression <|
\_ ->
{ expression = Exp.Integer intVal
, annotation = annotation
, imports = imports
}
}
)


{-| -}
aliasAs : String -> Arg arg -> Arg ( arg, Expression )
aliasAs aliasName (Arg toArgDetails) =
Expand Down

0 comments on commit aaf9daf

Please sign in to comment.