JuliaWeb / Hyperscript.jl

Hyperscript: A lightweight DOM representation for Julia
Other
101 stars 11 forks source link

Make flat accept AbstractArray #31

Closed schneiderfelipe closed 3 years ago

schneiderfelipe commented 3 years ago

Fix #30.

@yurivish I could add a test for this if you like, but that would probably add an extra test dependency.

yurivish commented 3 years ago

Thanks @schneiderfelipe!

I think you should be able to test this by choosing an AbstractArray from Base that is other than the concrete type Array. A BitVector, for example:

julia> BitArray([0, 0, 1, 1, 0])
5-element BitVector:
 0
 0
 1
 1
 0

julia> BitArray([0, 0, 1, 1, 0]) isa Array
false
schneiderfelipe commented 3 years ago

@yurivish Nice! I added a test with BitVector.

I had to add an extra case for AbstractRanges, as they are AbstractArrays as well, in order to avoid flattening:

julia> using Hyperscript

julia> const p = m("p")
<p></p>

julia> p([1, 2, 3])
<p>123</p>

julia> p(BitVector([0, 1, 0]))
<p>falsetruefalse</p>

julia> p(1:3)
<p>1:3</p>
yurivish commented 3 years ago

That's a good thought. Thanks for working on this!