If you're actually parsing a string, you may also want to look into one of
the various parsing libraries like `elm-tools/parser`. If you're willing to
give a few more details about the format of those strings, I'm sure people
here (and on slack) would be more than willing to give you a hand in
figuring things out.
Another alternative, in the same vein as Peter's proposals but including
more crimes against humanity (and loosely resembling Haskell's guard
syntax) is this one: https://ellie-app.com/46bdfm75sqja1/0
Op dinsdag 22 augustus 2017 14:46:11 UTC+2 schreef David Legard:
>
> Does Elm have anything between an *if-then-else* flow control and* case* ?
>
> My use case is, I need to parse a string in various ways to decide which
> Analysis ADT to assign to the string.
>
> Thus
>
> sconvert : String -> Analysis
> sconvert s =
> if s=="all" then AllDays
> else if s=="unplayed" then Unplayed
> else if String.startsWith "onday" s then OnDay (secondBit s)
> else if String.contains "totz:" s then Totz (secondBit s)
> else Unknown
>
>
> There are about 30 different branches in my app, and it's convenient to
> keep them together.
>
> I can't use a case expression here, so I guess what I'm looking for is
> something like F#'s match expression, where you can add conditions using
> the when modifier. (code written as if the function existed in Elm
>
> fizzBuzz : Int -> String
> fizzBuzz x =
> match x with
> | i when i % 15 = 0 -> "fizzbuzz"
> | i when i % 3 = 0 -> "fizz"
> | i when i % 5 = 0 -> "buzz"
> | i -> toString(i)
>
> What would be an elegant way to implement the fizzBuzz function in Elm?
>
>
--
You received this message because you are subscribed to the Google Groups "Elm
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.