It's only syntactic sugar for an anonymous function, but you can use a do block:
function adults(h::House)
return count(h.people) do person
person.age > 18
end
end
Closer to what you wrote in the comment is
adults(h::House) = count(getproperty.(h.people, :age) .> 18)
But this is somewhat less readable (there's no sugar for property broadcasting), and construct an unnecessary intermediate array.
There's a somewhat intermediate form using a generator, which doesn't add excessive memory:
adults(h::House) = count(person.age > 18 for person in h.people)
This is probably what I'd go for.
Finally, let it be said that of all versions, the one you wrote is not really less idiomatic, and will most likely be the fastest of all in a micro-benchmark, although I'd write it like this:
function adults(h::House)
count = 0
for i in eachindex(h.people)
count += Int(h.people[i].age > 18)
end
return count
end
Finally finally: this function is a natural map-reduce task, opening more possibilities if you go for purely functional approaches (like using Transducers or @distributed for).