https://toitlang.org/ logo
I still find myself being able to return
# general
a
I still find myself being able to return from lambdas xD
f
Can you refresh my memory. What was that about?
a
I always end up writing code like this
Copy code
filteredInbox := comms.inbox "filtered" --filter=(::
    return it.type == messages.Heartbeat.MT
  )
Only to remember that doesnt work 😛
f
aah. I was afraid it would actually do a return out of the function 🙂
k
Can't you use a block here?
a
Potentially, and if so, I am misunderstanding the docs 🙂
k
So you want to use the filter as a predicate that returns true or false.
a
Right, so the pattern I was aiming for is creating an inbox (wrapper around a toit channel) that has a filter that it can apply whenever something tries to get added to the inbox As a result the filter would need to be stored and used later And quoting from the docs
Lambdas can be stored and used later.
and
lambdas cannot use return at all.
But also
Blocks cannot.
be stored
f
In general
return
always returns from the current method. It never just leaves the current block or lambda. I think you would like it to just return from the lambda. In both cases (blocks and lambdas), either the last value is automatically returned, or you can use a
continue.XXX
to "continue in XXX". So in your case it would be
Copy code
filtered-inbox := comms.inbox "filtered" --filter=(:: continue.inbox it.type == messages.Heartbeat.MT)
We did consider having a different keyword (like
ret
) but never agreed that this was a good idea.