question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add mapping to lists of objects

See original GitHub issue

While using this library I constantly find myself repeating this over and over again:

      Cursor cursor = dbHelper.getReadableDatabase()
        .rawQuery(SomeModel.SELECT_SOMETHING);
      List<SomeModel> models = new ArrayList<>(cursor.getCount());
      while (cursor.moveToNext()) {
        models.add(SomeModel.MAPPER.map(cursor));
      }
      cursor.close();
      return models;

Do you plan on introducing something like LIST_MAPPER.map(cursor) or any utility function which would do the same? Of course, I could introduce my own helper in my codebase, but I thought it might be such a common pattern that library might have it too. Or do I miss something here?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
JakeWhartoncommented, Jun 13, 2016

QueryObservable.mapToList (or Query.mapToList). We use it with Retrolambda/Jack so that you can use a method reference:

db.createQuery(…) .mapToList(User.MAPPER::map) .subscribe(…)

On Mon, Jun 13, 2016 at 11:06 AM Kevin Most notifications@github.com wrote:

What’s that convenience method in SQLBrite? I use the two of these libraries together and ended up writing my own util method. Didn’t realize one was built-in.

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/square/sqldelight/issues/327#issuecomment-225609472, or mute the thread https://github.com/notifications/unsubscribe/AAEEEYTPCKdk4npJGQmDigs58_oNDs9gks5qLXH-gaJpZM4I0M3m .

0reactions
AlecStrongcommented, Jun 15, 2016

I’m gonna close this for now. In the future we’ll probably have tighter links between SQLDelight and SQLBrite but at least for we’ll keep functionality separate between them

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to add the map objects to the List in java - Stack Overflow
To create a list: List<Map<Object, Object> myList = new ArrayList<>();. Then use myList.add(map) to add maps to this list.
Read more >
How To Use .map() to Iterate Through Array Items in JavaScript
One of the most popular methods is the .map() method. .map() creates an array from calling a specific function on each item in...
Read more >
Mapping Lists with ModelMapper - Baeldung
In this tutorial, we explained how lists are mapped by manipulating generic types in ModelMapper. We can make use of TypeToken, generic type ......
Read more >
Build Maps Marker Layer with Related Lists - Salesforce Help
Check out the video below for steps to add related list to a Maps Marker Layer in Salesforce Maps ... Choose a Related...
Read more >
Array.prototype.map() - JavaScript - MDN Web Docs
The map() method creates a new array populated with the results of calling a provided function on every element in the calling array....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found