Slicing the RowIndex fails because of sub-list

hello,

I try to slice a list, using listcombine() and it fails

I use this formula and this works fine if I create a list manually. Once a part of the list is the outcome of a filter, it fails.

Sequence(1,3).FormulaMap(thisRow.thelist.Slice(thisRow.thelist.nth(CurrentValue),thisRow.thelist.Nth(CurrentValue)+1))

It keeps me already busy for a while and I looked into the difference between list() and listcombine(), but this did not help me.

the background is that I am trying to get the values in between breaks. so if a break ends at 6pm and driving ends at 9pm, it is 3 hours driving. That calculation is not the issue once I can slice as intended, but slicing the outcome of a filter is not so evident it appears.

thanks a lot!, Christiaan

Hi there @Christiaan_Huizer :blush: !

I’m no FormulaMap() expert (still learning about this versatile formula :innocent: ), and I haven’t been using Slice() a lot but I just think the Nth() are not necessary in your Slice() formula.

As when using Slice(), you’re already indicating a position where it should start and end, making Nth() useless (I think :innocent: ). I was still able to make the formula work using Slice() + Nth() (see the field Failure) but I’m pretty sure some part are redundant (feels like it, at least :sweat_smile: )

Anyway, I did play a little bit with your doc (after copying it :wink: ) and ended up with this formula :

Sequence(1,thisRow.thelist.Count()-1).FormulaMap(thisRow.thelist.Slice(CurrentValue,CurrentValue+1))

Which seems to work :blush: .

I did try another approach (see List() 1 + 2 ) as your post made me think about something I asked some time ago :blush: and kind of took as an inspiration the answer Paul gave me :blush: .

2 Likes

un grand merci @Pch !

very interesting approaches. I work a lot with Nth() and Slice(), but I might have overcomplicated the issue. The rather straightforward solution does the job.

Sequence(1,thisRow.thelist.Count()-1).FormulaMap(thisRow.thelist.Slice(CurrentValue,CurrentValue+1))

I want to understand better when to apply List() and when ListCombine(). The documentation is not very clear in this regard.

many thanks again! Christiaan

1 Like

@Christiaan_Huizer : You’re welcome :wink: !

As I also tend to overcomplicate things :sweat_smile: , I’ll admit that it took me a while to find the simple solution :sweat_smile: !

As for List() and ListCombine() @BenLee mentioned this in another topic :blush:

Which I think, is the main difference between the two :blush: .

As for knowing which one is best, I think it really depends on the use :innocent: .

But, I’ve created few examples using List() and ListCombine() in my sample below :blush: . It might give you a better idea on how they both work :wink: .

2 Likes

this is again a wonderful contribution @Pch !

This overview clarifies the differences very well.

When I started with Coda I had the tendency to use ListCombine() most of the time, it is only rather recent I noticed how valuable it is to keep the list() in a list (thus as sub lists) ‘alive’ as starting point for further calcuations.

enjoy your evening!, Christiaan

1 Like

You’re welcome again :wink: !

And enjoy your evening too :grin: !