ngs icon indicating copy to clipboard operation
ngs copied to clipboard

Implement '.'(Iter, Str)

Open ilyash-b opened this issue 6 years ago • 3 comments

... allowing Iter(something).my_field

ilyash-b avatar Jan 11 '19 06:01 ilyash-b

Currently this works: [{"x": 1}, {"x": 2}].x == [1, 2]. That's because of definition: F .(a:Arr, field:Str) a.map(X.(field)) in stdlib.ngs.

Same .my_field operation should work on Iter objects: my_iter.x but it should return an Iter object, not an array. That's in order to be able to have a chain of Iters, for processing potentially endless stream. At no point of Iter chain.

See

  • Iter.ngs, particularly MapIter. It should be pretty close to what needs to be implemented here.
  • F .(a:Arr, field:Str) in stdlib.ngs

ilyash-b avatar Sep 28 '22 07:09 ilyash-b

which fields can an Iterator have? what is the really purpose of implementing this?

antonio-pedro99 avatar Oct 16 '22 22:10 antonio-pedro99

This is supposed to be the equivalent of F .(Arr, Str) which is defined as F .(a:Arr, field:Str) a.map(X.(field)) but for Iters.

The . operation should be applied to items that the Iter returns (when next() is called).

Unfortunately, there is a design issue here. Arr objects don't have any fields so my_arr.my_field can be used to reference the fields of the elements. Iter has fields so my_iter.my_field can not be freely repurposed. One possible solution would be to move all the fields of Iter into meta() like ArrLike does. Open to hear other suggestions.

ilyash-b avatar Oct 19 '22 07:10 ilyash-b