# Can you use a code block as a List.Map function?

**URL:** <https://forum.dynamobim.com/t/can-you-use-a-code-block-as-a-list-map-function/38319>\
**Category:** Uncategorized\
**Created:** [July 15, 2019, 9:24pm UTC](https://forum.dynamobim.com/t/can-you-use-a-code-block-as-a-list-map-function/38319 "2019-07-15T21:24:47Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![RealHandy](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/realhandy/32/76579_2.png) [@RealHandy](https://forum.dynamobim.com/u/RealHandy)\
**Post date:** [July 15, 2019, 9:24pm UTC](https://forum.dynamobim.com/t/can-you-use-a-code-block-as-a-list-map-function/38319/1 "2019-07-15T21:24:48Z")

</div>

I’m passing a list of custom objects from a ZTN into List.Map. I think I should be able to write a code block that returns an attribute from each of the objects in the list, like this:  
 ![mapfunction](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/7/c/7c63bd2d8fa241f86abe8c5e2cfc7cb3eff05cda.png)  
But no matter what I try, I just get an error that my code block is dereferencing a non-pointer. Which is not true – I have no null items in my list. So is there no way to do this?

Thanks!

---

<div class="post-metadata">

**Author:** ![Nick\_Boyts](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/nick_boyts/32/76313_2.png) [@Nick\_Boyts](https://forum.dynamobim.com/u/Nick_Boyts)\
**Post date:** [July 15, 2019, 9:30pm UTC](https://forum.dynamobim.com/t/can-you-use-a-code-block-as-a-list-map-function/38319/2 "2019-07-15T21:30:28Z")

</div>

What Dynamo version are you using? List levels would probably be easier.

---

<div class="post-metadata">

**Author:** ![jacob.small](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jacob.small/32/161030_2.png) [@jacob.small](https://forum.dynamobim.com/u/jacob.small)\
**Post date:** [July 16, 2019, 1:07am UTC](https://forum.dynamobim.com/t/can-you-use-a-code-block-as-a-list-map-function/38319/3 "2019-07-16T01:07:56Z")

</div>

> [@Nick\_Boyts](#):
>
> List levels would probably be easier.

This 100x over.

---

<div class="post-metadata">

**Author:** ![Michael\_Kirschner2](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/michael_kirschner2/32/75576_2.png) [@Michael\_Kirschner2](https://forum.dynamobim.com/u/Michael_Kirschner2)\
**Post date:** [July 16, 2019, 2:00am UTC](https://forum.dynamobim.com/t/can-you-use-a-code-block-as-a-list-map-function/38319/4 "2019-07-16T02:00:18Z")

</div>

you can - you need to use FunctionObject constructor…

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/3/c/3cb760ec6823703a84c6bc7606e3393d39840ac7.jpeg)

---

<div class="post-metadata">

**Author:** ![RealHandy](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/realhandy/32/76579_2.png) [@RealHandy](https://forum.dynamobim.com/u/RealHandy)\
**Post date:** [July 16, 2019, 7:23pm UTC](https://forum.dynamobim.com/t/can-you-use-a-code-block-as-a-list-map-function/38319/5 "2019-07-16T19:23:58Z")

</div>

It’s Dynamo 2. I’ll look into list levels. Thanks!

(btw, I really appreciate how quickly you guys respond to these noob questions)

---

<div class="post-metadata">

**Author:** ![RealHandy](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/realhandy/32/76579_2.png) [@RealHandy](https://forum.dynamobim.com/u/RealHandy)\
**Post date:** [July 16, 2019, 8:11pm UTC](https://forum.dynamobim.com/t/can-you-use-a-code-block-as-a-list-map-function/38319/6 "2019-07-16T20:11:40Z")

</div>

So it turned out that I solved my problem by not even trying to access each element in the list. I passed the _list_ into a code block node that was just this:  
`program ? program.Quantity : null`

And then passed the output of that code block into the next node, and voila! Somehow, Dynamo realized that the code block was receiving a _list_ of programs, _applied the code block to each element in the list_, and output a _list_ of Quantitys to the next node. And the next node (not pictured in this thread) knew to apply _itself_ to every element of the incoming list, even though it also was showing it expected a single item input, rather than a list of that item. That is some interesting “yeah, I can tell what you mean to do even though your inputs and outputs are lists instead of single items” stuff.

---

<div class="post-metadata">

**Author:** ![Nick\_Boyts](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/nick_boyts/32/76313_2.png) [@Nick\_Boyts](https://forum.dynamobim.com/u/Nick_Boyts)\
**Post date:** [July 16, 2019, 9:09pm UTC](https://forum.dynamobim.com/t/can-you-use-a-code-block-as-a-list-map-function/38319/7 "2019-07-16T21:09:59Z")

</div>

Dynamo uses a kind of “internal” lacing (now Auto in 2.X). It’s usually smart enough to determine the kind of input it’s receiving and how it needs to be handled.

A node with an “item” input that receives a list knows to iterate through each item individually.  
A node with a “list” input may need some additional information to know how to handle a list of lists.  
A node with multiple inputs will need additional information to know how to handle mismatched input types.

These situations all get handled by lacing or list levels.
