turbine: Return value is not chained?

I was expecting both elements to show up but only first one did:

function* main() {
  yield label('Please enter your name:')
  return input()
}

It does show up when I remove the yield:

function* main() {
  return input()
}

A bug or feature? 😃

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 16 (16 by maintainers)

Most upvoted comments

const safeDiv = (n, m) => m === 0 ? nothing : just(n / m);
go(function*() {
  const a = yield find(isEven, list1);
  const b = yield find(isEven, list2);
  const c = yield safeDiv(a, b)
  return a + b + c;
});

… My guess is that the list is like array monad here and the end result is wrapped into the list as in Haskell.

No, It is not the list/array monad. According to Jabz documentation, find returns a Maybe<A> which is either a just a or nothing. This makes sense, since searching for something in a list, will only maybe give you a result otherwise nothing.

Chaining a Maybe is like saying: “Calculate this unless you get a nothing, in that case, the whole result is nothing” since go-notation is just sugar for calling chain, the example returns nothing if any of the yielded functions returns nothing otherwise it returns just d where d is the result of the computation.

Transferring to the Component monad case here, that should mean the return value is wrapped into the Component.

yes, this is correct.

But what does it mean for the returned empty object {} in this example: …

it means that if main were made to a Component using go-notation, running/yielding this component would return {}.