zero-functional / zero-functional

A library providing zero-cost chaining for functional abstractions in Nim.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Feature request]: take result's field names from variables

data-man opened this issue · comments

For example:

import zero_functional

let a = @[2, 8, -4]
let b = @[0, 1, 2]
let c = @[5, 6, 7]

let res = zip(a, b, c) --> map(it)

echo res

Outputs:
@[(Field0: 2, Field1: 0, Field2: 5), (Field0: 8, Field1: 1, Field2: 6), (Field0: -4, Field1: 2, Field2: 7)]

Proposal:
@[(a: 2, b: 0, c: 5), (a: 8, b: 1, c: 6), (a: -4, b: 2, c: 7)]

Maybe optionally with some define.

Looks like a nice extension - however it is also possible to zip the same list several times - like
zip(a,a,a)
Any idea how to name that? Easiest way would maybe be indexing all fields - like this maybe:
(a0: 2, b1: 0, c2: 5) - just to be consistent with Field0 etc. Or maybe (a_0: 2, b_1: 0, c_2: 5) ?

... also this is of course not possible for more complex expressions such as
zip(@[1,2,3], a)

(a0: 2, b1: 0, c2: 5)

Yes, it's fine.

OK - implementation done. Can be closed.

Thank you!

Is it very difficult to detect 'simple' cases and produce names without numbers?

🙄 no - it is actually not that difficult....
OK - I added some simple enough check - but: simple really means: when all labels are different. If any labels are equal numbers are added to all of the labels. See also test.nim.

Great, perfectly!