Elixir does not have the keyword “break out”, which would be equivalent to the keyword “return” in other languages.
Typically, you should restructure your code so that the last statement executed returns a value.
The following is an idiomatic way for an elixir to do the equivalent of your code test, assuming you meant “a” as something that behaves like an array, as in your original example:
def is_there_a_22(a) do Enum.any?(a, fn(item) -> item == "22" end.) end
What is really going on here, we are rebuilding our thinking a bit. Instead of a procedural approach, where we will look for an array and return earlier, if we find what we were looking for, we will ask what you really do in the code fragment: "Does this array have 22 anywhere?"
Then we are going to use the Enum elixir library to run through the array and provide the any? with a test that will tell us if anything meets the criteria we cared about.
Although this is a case that can be easily solved with the help of an enumeration, I think that perhaps the basis of your question relates more to such things as the “embroidery pattern” used in procedural methods. For example, if I meet certain criteria in a method, return immediately. A good example of this would be a method that returns false if the thing you're going to work on is null:
function is_my_property_true(obj) { if (obj == null) { return false; }
The only way to achieve this in the elixir is to set a guard and decompose the method:
def test_property_val_from_obj(obj) do # ...a bunch of code about to get the property # want and see if it is true end def is_my_property_true(obj) do case obj do nil -> false _ -> test_property_value_from_obj(obj) end end
tl; dr - No, there is no equivalent - you need to structure your code accordingly. On the other hand, this leads to the fact that your methods are small - and your intention is clear.