Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to check whether a type is iterable within Julia's type system?

Tags:

julia

Collections in Julia need to support three functions to be iterable: start, next, and done.

Is there currently a way to express that an input x to a function needs to be iterable within the type system? If not, is this on the roadmap?

like image 963
Ben Hamner Avatar asked Oct 13 '14 22:10

Ben Hamner


1 Answers

Is it possible? Yes, but not in a very elegant way:

julia> x = 1:5
1:5

julia> applicable(start, x)
true

julia> applicable(next,x,start(x))
true

julia> applicable(done,x,start(x))
true

I'm not sure how to get around the need for the start(x)s - maybe checking for start will be "good enough".

As for a more sensible way, this would need multiple inheritance or interfaces, which is under discussion, e.g. here is one issue, it links to others.

like image 88
IainDunning Avatar answered Sep 27 '22 22:09

IainDunning