fantasyland / sweet-fantasies

sweet.js macros for Fantasy Land compatible structures.
34 stars 7 forks source link

If/else #2

Closed markandrus closed 11 years ago

markandrus commented 11 years ago

@jonifreeman How should if/else be handled in do-notation? ae017ac22cc962d5f47c555f9afd06573c6af483 is one approach, but maybe a little noisy?

jonifreeman commented 11 years ago

That syntax looks good to me. In Haskell the same is written as:

do
  a <- foo
  if a == 10 
    then do
      b <- bar
      return b
    else do 
      c <- quux
      return c

Which is about the same sans curlies and brackets.

I'd like too see support for this common case too though:

$do {
  a <- foo
  if (a == 1) return bar else return quux
}

Do you see any problems in adding that too?

markandrus commented 11 years ago

@jonifreeman Thanks for taking a look. I agree we should support the case you mentioned, and have since added it, as well as support for else ifs. Latest commit: faccfc5

jonifreeman commented 11 years ago

Great! Please merge this to master whenever you like.

markandrus commented 11 years ago

Merged: c46edaccd668c086cae7d5f30d7577c2df0114bd