Outer Consturctor with Parametric Types + Iterator Question

When I try to create a Lapper, I get the following error.

julia version 1.1.0
 inputs = [Interval(3, 5, true), Interval(4, 10, false), Interval(7, 12, true), Interval(9, 15, true), Interval(7, 10, true)]
5-element Array{Interval{Bool},1}:
 Interval{Bool}(3, 5, true)
 Interval{Bool}(4, 10, false)
 Interval{Bool}(7, 12, true)
 Interval{Bool}(9, 15, true)
 Interval{Bool}(7, 10, true)

 lapper = Lapper(inputs)
ERROR: MethodError: no method matching Lapper(::Array{Interval{Bool},1})
Closest candidates are:
  Lapper(::Array{Interval{T},1}, ::Int64, ::Int64, ::Union{Nothing, Int64}, ::Bool) where T at main.jl:11
Stacktrace:
 [1] top-level scope at none:0

Why isn’t my constructor listed as a possible method?

Part two of my question is in regards to the find method. I want to return an iterator, and I believe what I have will work, but is it idiomatic / performant?

Drop the {T} in the definition of the constructor Lapper{T}(intervals::Vector{Interval{T}}) where T and you should be fine.

I.e. make it Lapper(intervals::Vector{Interval{T}}) where T

2 Likes