sorted

Creator: coderz1093

Last updated:

0 purchases

sorted Image
sorted Images

Languages

Categories

Add to Cart

Description:

sorted

sorted #


Sort lists of complex objects with ease. Simple but powerful extension method.
auctions.sorted([
SortedOrdered<Auction, AuctionStatus>(
(action) => auction.buyerContext.status,
[AuctionStatus.live, AuctionStatus.won, AuctionStatus.lost],
),
SortedComparable<Auction, DateTime>((auction) => auction.endedAt),
SortedComparable<Auction, DateTime>(
(auction) => auction.endedAt,
invert: true,
)
]);
copied to clipboard
Usage #
Add the package to your pubspec.yaml:
dependencies:
sorted: <newest version>
copied to clipboard
Import the package:
import 'package:sorted/sorted.dart';
copied to clipboard
Call sorted extension method on any list and pass sorting rules of your choice. Order matters, so if first rule considers two items equal, next one will decide and so on.
Sorting rules #
All rules have an optional named argument invert which inverts the sorting order.
SortedOrdered #
SortedOrdered<Auction, AuctionStatus>(
(auction) => auction.buyerContext.status,
[AuctionStatus.live, AuctionStatus.won, AuctionStatus.lost],
)
copied to clipboard
Sorts items by the mapped property value in an order passed as a second argument. In this example, live auctions will be first, then won, and then lost.
SortedGroupOrdered #
SortedOrdered<Road, RoadType>(
(road) => road.type,
[
[RoadType.nationalHighway, RoadType.stateHighway],
[RoadType.district],
[RoadType.dirt],
],
)
copied to clipboard
Sorts items by the mapped property value in the order of order groups, but all values withing a certain group are considered equal.
SortedComparable #
SortedComparable<User, String>((user) => user.lastName)
copied to clipboard
Sorts items by the mapped property value using Comparable.compare which is basically a.compareTo(b). Sorts strings alphabetically, numbers ascending, etc.
SortedComparator #
SortedComparator<Auction, String>(
(auction) => auction.buyerContext.status,
(a, b) => /* your custom compare function */,
)
copied to clipboard
Sorts items by the mapped property value using a custom comparator provided as a second argument.

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.