Quick actions

cmd+k|ctrl+k

Navigation

Languages

sliced_seq

Snippet info

Language

Nim

Visibility

public

Author

oderwat

Created

2016-06-21T09:52:28Z

Updated

2016-06-21T09:52:28Z

type SeqView[T] = object
  data: ref seq[T]
  bounds: Slice[int]

proc box[T](x: T): ref T =
  new(result); result[] = x

iterator items[T](sv: SeqView[T]): T =
  for pos in sv.bounds:
    yield sv.data[pos]

var
  seq1 = @[1, 2, 3, 4, 5, 6]
  sv = SeqView[int](data: box(seq1), bounds: 2..4)

for el in sv:
  echo el
INFO