[julia-users] Re: is it possible for collect() to return a collection of a specific type?

2015-11-27 Thread elextr
Collect only requires that the collection is iterable, for which providing 
an eltype() function is optional.  I don't know if it is possible to check 
at runtime if eltype() exists for the collection then it could use that 
instead of Any, otherwise it would have to iterate the collection to find 
all the types and either accumulate the results in an Any collection as it 
goes and copy them to the right type collection later, or iterate twice.

On Saturday, November 28, 2015 at 10:17:09 AM UTC+10, Seth wrote:
>
> Well, I just found collect(Edge, edges(g)) works, but it would be nice if 
> collect() returned a vector of Edge by default. Any ideas?
>
> On Friday, November 27, 2015 at 3:46:58 PM UTC-8, Seth wrote:
>>
>> I have implemented my own iterator that works against edges in a graph, 
>> and edges(g) returns the iterator. However, collect(edges(g)) returns an 
>> array of Any,1. I'd like it to return an array of Edge, 1. What am I 
>> missing?
>>
>>

[julia-users] Re: is it possible for collect() to return a collection of a specific type?

2015-11-27 Thread Seth
That did it - thank you!

For the archives:

eltype(::Type{EdgeIter}) = Edge


On Friday, November 27, 2015 at 5:29:20 PM UTC-8, Dan wrote:
>
> Looking at the collect code, it seems you really should define Base.eltype 
> for 
> your iterator and things will work out.
>
> On Saturday, November 28, 2015 at 3:15:18 AM UTC+2, Seth wrote:
>>
>> I guess that makes sense, though I struggle to see why one would create 
>> an iterator that produces multiple types.
>>
>> On Friday, November 27, 2015 at 4:45:26 PM UTC-8, ele...@gmail.com wrote:
>>>
>>> Collect only requires that the collection is iterable, for which 
>>> providing an eltype() function is optional.  I don't know if it is possible 
>>> to check at runtime if eltype() exists for the collection then it could use 
>>> that instead of Any, otherwise it would have to iterate the collection to 
>>> find all the types and either accumulate the results in an Any collection 
>>> as it goes and copy them to the right type collection later, or iterate 
>>> twice.
>>>
>>> On Saturday, November 28, 2015 at 10:17:09 AM UTC+10, Seth wrote:

 Well, I just found collect(Edge, edges(g)) works, but it would be nice 
 if collect() returned a vector of Edge by default. Any ideas?

 On Friday, November 27, 2015 at 3:46:58 PM UTC-8, Seth wrote:
>
> I have implemented my own iterator that works against edges in a 
> graph, and edges(g) returns the iterator. However, collect(edges(g)) 
> returns an array of Any,1. I'd like it to return an array of Edge, 1. 
> What am I missing?
>
>

[julia-users] Re: is it possible for collect() to return a collection of a specific type?

2015-11-27 Thread Dan
have you tried running collect within a function? sometimes the Global 
scope is bad for type inference.

On Saturday, November 28, 2015 at 2:45:26 AM UTC+2, ele...@gmail.com wrote:
>
> Collect only requires that the collection is iterable, for which providing 
> an eltype() function is optional.  I don't know if it is possible to check 
> at runtime if eltype() exists for the collection then it could use that 
> instead of Any, otherwise it would have to iterate the collection to find 
> all the types and either accumulate the results in an Any collection as it 
> goes and copy them to the right type collection later, or iterate twice.
>
> On Saturday, November 28, 2015 at 10:17:09 AM UTC+10, Seth wrote:
>>
>> Well, I just found collect(Edge, edges(g)) works, but it would be nice 
>> if collect() returned a vector of Edge by default. Any ideas?
>>
>> On Friday, November 27, 2015 at 3:46:58 PM UTC-8, Seth wrote:
>>>
>>> I have implemented my own iterator that works against edges in a graph, 
>>> and edges(g) returns the iterator. However, collect(edges(g)) returns 
>>> an array of Any,1. I'd like it to return an array of Edge, 1. What am I 
>>> missing?
>>>
>>>

[julia-users] Re: is it possible for collect() to return a collection of a specific type?

2015-11-27 Thread Seth
I guess that makes sense, though I struggle to see why one would create an 
iterator that produces multiple types.

On Friday, November 27, 2015 at 4:45:26 PM UTC-8, ele...@gmail.com wrote:
>
> Collect only requires that the collection is iterable, for which providing 
> an eltype() function is optional.  I don't know if it is possible to check 
> at runtime if eltype() exists for the collection then it could use that 
> instead of Any, otherwise it would have to iterate the collection to find 
> all the types and either accumulate the results in an Any collection as it 
> goes and copy them to the right type collection later, or iterate twice.
>
> On Saturday, November 28, 2015 at 10:17:09 AM UTC+10, Seth wrote:
>>
>> Well, I just found collect(Edge, edges(g)) works, but it would be nice 
>> if collect() returned a vector of Edge by default. Any ideas?
>>
>> On Friday, November 27, 2015 at 3:46:58 PM UTC-8, Seth wrote:
>>>
>>> I have implemented my own iterator that works against edges in a graph, 
>>> and edges(g) returns the iterator. However, collect(edges(g)) returns 
>>> an array of Any,1. I'd like it to return an array of Edge, 1. What am I 
>>> missing?
>>>
>>>

[julia-users] Re: is it possible for collect() to return a collection of a specific type?

2015-11-27 Thread Seth
Yup. That's actually where I was using it.

On Friday, November 27, 2015 at 5:15:10 PM UTC-8, Dan wrote:
>
> have you tried running collect within a function? sometimes the Global 
> scope is bad for type inference.
>
> On Saturday, November 28, 2015 at 2:45:26 AM UTC+2, ele...@gmail.com 
> wrote:
>>
>> Collect only requires that the collection is iterable, for which 
>> providing an eltype() function is optional.  I don't know if it is possible 
>> to check at runtime if eltype() exists for the collection then it could use 
>> that instead of Any, otherwise it would have to iterate the collection to 
>> find all the types and either accumulate the results in an Any collection 
>> as it goes and copy them to the right type collection later, or iterate 
>> twice.
>>
>> On Saturday, November 28, 2015 at 10:17:09 AM UTC+10, Seth wrote:
>>>
>>> Well, I just found collect(Edge, edges(g)) works, but it would be nice 
>>> if collect() returned a vector of Edge by default. Any ideas?
>>>
>>> On Friday, November 27, 2015 at 3:46:58 PM UTC-8, Seth wrote:

 I have implemented my own iterator that works against edges in a graph, 
 and edges(g) returns the iterator. However, collect(edges(g)) returns 
 an array of Any,1. I'd like it to return an array of Edge, 1. What am 
 I missing?



[julia-users] Re: is it possible for collect() to return a collection of a specific type?

2015-11-27 Thread Dan
Looking at the collect code, it seems you really should define Base.eltype for 
your iterator and things will work out.

On Saturday, November 28, 2015 at 3:15:18 AM UTC+2, Seth wrote:
>
> I guess that makes sense, though I struggle to see why one would create an 
> iterator that produces multiple types.
>
> On Friday, November 27, 2015 at 4:45:26 PM UTC-8, ele...@gmail.com wrote:
>>
>> Collect only requires that the collection is iterable, for which 
>> providing an eltype() function is optional.  I don't know if it is possible 
>> to check at runtime if eltype() exists for the collection then it could use 
>> that instead of Any, otherwise it would have to iterate the collection to 
>> find all the types and either accumulate the results in an Any collection 
>> as it goes and copy them to the right type collection later, or iterate 
>> twice.
>>
>> On Saturday, November 28, 2015 at 10:17:09 AM UTC+10, Seth wrote:
>>>
>>> Well, I just found collect(Edge, edges(g)) works, but it would be nice 
>>> if collect() returned a vector of Edge by default. Any ideas?
>>>
>>> On Friday, November 27, 2015 at 3:46:58 PM UTC-8, Seth wrote:

 I have implemented my own iterator that works against edges in a graph, 
 and edges(g) returns the iterator. However, collect(edges(g)) returns 
 an array of Any,1. I'd like it to return an array of Edge, 1. What am 
 I missing?



[julia-users] Re: is it possible for collect() to return a collection of a specific type?

2015-11-27 Thread Seth
Well, I just found collect(Edge, edges(g)) works, but it would be nice if 
collect() returned a vector of Edge by default. Any ideas?

On Friday, November 27, 2015 at 3:46:58 PM UTC-8, Seth wrote:
>
> I have implemented my own iterator that works against edges in a graph, 
> and edges(g) returns the iterator. However, collect(edges(g)) returns an 
> array of Any,1. I'd like it to return an array of Edge, 1. What am I 
> missing?
>
>