Range with extra end? Is posible?

How to create silimilar this vector range()

julia> [1:10:40;45]
5-element Array{Int64,1}:
  1
 11
 21
 31
 45

I expect something like :

collect(range( x,y,z,;?)
1
11
21
31
45

Thx, Paul

Are you looking for

julia> vcat(range(1, 40, step=10), 45)
5-element Array{Int64,1}:
  1
 11
 21
 31
 45

?

1 Like

Also:

vcat(1:10:40,45)
1 Like

No, a range cannot describe that sequence. Only uniformly spaced sequences are possible.

1 Like

So Iterators.flatten((0:3:10, 12)) creates an iterator corresponding to your example,

julia> collect(Iterators.flatten((0:3:10, 12)))
5-element Array{Int64,1}:
  0
  3
  6
  9
 12

but it is not guaranteed that this will work everywhere where you could use a Range, so for example it does not support getindex.

4 Likes

Thanks… si only vec. :slight_smile: