# Return outer function in do block

**URL:** <https://discourse.julialang.org/t/return-outer-function-in-do-block/35660>\
**Category:** New to Julia\
**Created:** [March 6, 2020, 8:02pm UTC](https://discourse.julialang.org/t/return-outer-function-in-do-block/35660 "2020-03-06T20:02:32Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [March 7, 2020, 1:25pm UTC](https://discourse.julialang.org/t/return-outer-function-in-do-block/35660/7 "2020-03-07T13:25:41Z")

</div>

I occasionally miss [`common-lisp:return-from`](http://www.lispworks.com/documentation/HyperSpec/Body/s_ret_fr.htm#return-from) in Julia, which has no such construct AFAIK.

A version of `map`, `mapreduce` & friends (`foldl` etc) that allow early termination (eg based on a sentinel value or a flag that is returned) could help in cases like this, and there is no reason a package could not implement these efficiently (maybe there is one already, I just missed it). Cf

> [@Terminating sum early](https://discourse.julialang.org/t/terminating-sum-early/15012):
>
> I am calculating a sum of values returned by a function, which is supposed to be type stable. The function may be costly, and returns values that are either finite or -Inf. In case of -Inf, I would like to return early. MWE (which is of course not costly, the first version does not return early): observation\_logdensity(μ, x) = x \> μ ? -abs2(x - μ) : oftype(promote(x, μ), -Inf) sample\_logdensity1(μ, xs) = sum(observation\_logdensity(μ, x) for x in xs) Now I am wondering how to program what I w…

---

_[View the full topic](https://discourse.julialang.org/t/return-outer-function-in-do-block/35660)._
