I don't know about elegant but one way to implement something like fizzBuzz would be: https://ellie-app.com/469wMYcvrZ3a1/0
Of course, this assumes that you have a lot of patterns and not the 4 in fizzBuzz If evaluating all the branches is too expensive you can use functions like this: https://ellie-app.com/469wMYcvrZ3a1/1 On Tue, Aug 22, 2017 at 3:46 PM, David Legard <daleg...@gmail.com> wrote: > 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. > -- There is NO FATE, we are the creators. blog: http://damoc.ro/ -- 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.