when-switch icon indicating copy to clipboard operation
when-switch copied to clipboard

Enable syntax `when.true`

Open kube opened this issue 8 years ago • 2 comments

To replace this use of the syntax :

when(true)
  .is(assertion, value)
  .is(assertion, value)
  .else(defaultValue)

Update when-switch to enable this syntax :

when
  .true(assertion, value)
  .true(assertion, value)
  .else(defaultValue)

kube avatar Dec 02 '16 19:12 kube

To permit lazy evaluation in case of side effects of assertion or simply to prevent unnecessary calculation, (e.g. if needs to call a function), permit assertion to be wrapped in a thunk.

when
  .true(obj.isBuffer(), true)
  .else(defaultValue)

Becomes

when
  .true(() => obj.isBuffer(), true)
  .else(defaultValue)

Then the thunk will be unwrapped only when evaluating the true node.

kube avatar Dec 02 '16 19:12 kube

#7 Hi, I know that this issue is already 3 years old but from all similar libraries I liked this one the most, so I wanted to improve it and I made an implementation of this syntax.

nawordar avatar Aug 29 '19 20:08 nawordar