GithubHelp home page GithubHelp logo

supposedlysam / chunk Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 7.22 MB

License: BSD 3-Clause "New" or "Revised" License

Dart 46.22% Kotlin 0.17% Swift 1.43% Objective-C 0.05% CMake 19.57% C++ 25.90% C 1.76% HTML 4.90%

chunk's Introduction

Used to paginate any type of data

Getting started

Simply use the Chunker class to select the value you'll be using as your identifier between chunks. Then supply a function to be called each time you need a new chunk from your data source. Once those are provided, a single function is all that's needed to infinitely walk through your data.

Usage

Set up

final chunker = Chunker<String, String>(
  cursorSelector: (v) => v,
  dataChunker: (cursor, limit) {
  final isFirstRun = cursor == null;

  return isFirstRun
    ? dataSource.take(limit)
    : dataSource
      .skipWhile((value) => value != cursor)
      .skip(1) // Start after the previous cursor
      .take(limit);
  },
);

Paginate

First Chunk

For the first chunk you can provide a new Chunk with a custom limit or provide null to accept the default limit of 20

final Chunk<String, String> nextChunk = await chunker.getNext(
  Chunk(limit: 15),
);

Remaining Chunks

For all future chunks, all you need to do is pass the previous chunk in.

await chunker.getNext(nextChunk);

Examples

Dart Example

Check out a simple Dart only example listing out US States in chunks.

Flutter Example

Check out a more complete Flutter example derived from the flutter infinite list example created for the bloc library.

chunk's People

Contributors

supposedlysam avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.