Alternative to custom node - functions?

So, i’ve been encountering this problem a few times lately, this is just an example.

I was trying to get an item from one list to the beggining of each of the sublists contained in another list. I tried using the List.AddToFront node but it didn’t do exactly what I wanted:

1

 

 

 

 

 

 

 

 

So I ended up finding a work around creating a custom node that would work as a function using list.map:

2

3

 

 

 

 

 

 

 

 

There must be a better way of doing this without having to create a custom node every time something like this happens. So I thought I would try to replicate what I’m doing with the custom node through functions, but it’s not working.

I see that the node List.AddItemToFront behaves differently when inside a function. It only reads the first element of each sublist. I tried all sorts of combinations but none of them worked.

4

 

 

 

 

 

 

 

 

 

 

Hope someone could share a bit of light on the subject. Thanks in advance.

additemtofront_problem

AddItemToFront_Custom

Hi Andre, i would have done it like this

or like this

As always, there’s alwayas an easier way! :slight_smile: first approach is very interesting, didn’t know the Transpose node could be used that way, very clever. The thing is that lately I’ve been biased to use functions, now that I’m realizing the full potential of such tools such as List.map, it’s like a new toy. Though in this case it didn’t do me much use because I had two variables. Didn’t realize List.Combine did the same thingas List.Map for two lists/variables. That’s why I really liked your second post. I was really focused on emulating the behaviour of my costum node through functions but I suppose it doesn’t make much sense anymore. Thanks Mostafa!

I think i know exactly what you mean. I tend to do the same. But i really learn a lot in this forum, particularly from guys like Vikram who always have simple and elegant solutions to those types of issues.