# Return hashmap as list

**URL:** <https://forum.dfinity.org/t/return-hashmap-as-list/6275>\
**Category:** Developers\
**Created:** [August 3, 2021, 8:49am UTC](https://forum.dfinity.org/t/return-hashmap-as-list/6275 "2021-08-03T08:49:36Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jakepeg](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/jakepeg/32/2471_2.png) [@jakepeg](https://forum.dfinity.org/u/jakepeg)\
**Post date:** [August 3, 2021, 8:49am UTC](https://forum.dfinity.org/t/return-hashmap-as-list/6275/1 "2021-08-03T08:49:36Z")

</div>

Hello!

I want to return a list of store entries in a hashmap (Motoko). I’ve tried various things but keep getting type errors. I think I’m missing something simple, but can’t figure it out!

```auto
  public query func list(): async [Child] {
    return Iter.toArray(store.entries());
  };

```

```auto
 type error [M0096], expression of type
  Iter/1<(Text, Text)> = {next : () -> ?(Text, Text)}
cannot produce expected type
  [Child/1]

```

---

<div class="post-metadata">

**Author:** ![rossberg](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/rossberg/32/795_2.png) [@rossberg](https://forum.dfinity.org/u/rossberg)\
**Post date:** [August 3, 2021, 11:21am UTC](https://forum.dfinity.org/t/return-hashmap-as-list/6275/2 "2021-08-03T11:21:32Z")

</div>

I think we’ll need more context. What is the type of `store`, and what is the definition of type `Child`?

---

<div class="post-metadata">

**Author:** ![jakepeg](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/jakepeg/32/2471_2.png) [@jakepeg](https://forum.dfinity.org/u/jakepeg)\
**Post date:** [August 3, 2021, 11:56am UTC](https://forum.dfinity.org/t/return-hashmap-as-list/6275/3 "2021-08-03T11:56:02Z")

</div>

this is my store

```auto
  stable var entries : [(Text, Text)] = [];

  let store: HM.HashMap<Text, Text> = HM.fromIter(entries.vals(), 16, Text.equal, Text.hash);

```

and this is the Child type def

```auto
  public type Child = {
    name: Text;
    child_id: Text;
  };

```

---

<div class="post-metadata">

**Author:** ![rossberg](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/rossberg/32/795_2.png) [@rossberg](https://forum.dfinity.org/u/rossberg)\
**Post date:** [August 3, 2021, 1:04pm UTC](https://forum.dfinity.org/t/return-hashmap-as-list/6275/4 "2021-08-03T13:04:26Z")

</div>

The problem is that your call to `Iter.toArray` produces a `[(Text, Text)]`, but your function is declared to return a `[Child]`. A Child is not a pair of Text.

FWIW, I cannot reproduce the error message you showed. I see:

```auto
cannot implicitly instantiate function of type
  <A>(Iter/7<A>) -> [A]
to argument of type
  Iter/7<(Text, Text)>
to produce result of type
  [Child/5]
because implicit instantiation of type parameter A is over-constrained with
  (Text, Text) <: A <: Child/5
where
  (Text, Text) </: Child/5
so that no valid instantiation exists

```

---

<div class="post-metadata">

**Author:** ![jakepeg](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/jakepeg/32/2471_2.png) [@jakepeg](https://forum.dfinity.org/u/jakepeg)\
**Post date:** [August 3, 2021, 2:35pm UTC](https://forum.dfinity.org/t/return-hashmap-as-list/6275/5 "2021-08-03T14:35:36Z")

</div>

Thanks, it works now
