Skip to content

ISortedSet #7

@opsb

Description

@opsb

I was very happy to find that https://pub.dev/documentation/fast_immutable_collections/latest/fast_immutable_collections/ISet-class.html can be configured to be sorted. In practice though I'm finding it difficult to ensure that a property that is specified as ISet is forced to remain sorted.

@freezed
abstract class TimelineChartData with _$TimelineChartData {
  const TimelineChartData._();

  factory TimelineChartData({
    @required Extent<DateTime> focusedRange,
    @required ISet<GlucoseReading> glucoseReadings,
    @required ISet<InsulinInjection> insulinInjections,
  }) = _TimelineChartData;

  factory TimelineChartData.from({
    @required Extent<DateTime> focusedRange,
    @required TimelineDataBatch batch,
  }) {
    return TimelineChartData(
      focusedRange: focusedRange,
      glucoseReadings: ISet<GlucoseReading>.withConfig(
          batch.glucoseReadings, ConfigSet(sort: true)),
      insulinInjections: ISet<InsulinInjection>.withConfig(
          batch.insulinInjections, ConfigSet(sort: true)),
    );
  }
}

In this example you can see from the factory TimelineChartData.from that I want both glucoseReadings and insulinInjections to be sorted. The problem is that whenever I replace glucoseReadings or insulinInjections I need to remember to configure the ISet to be sorted. By introducing ISortedSet it would allow the compiler to enforce that the set remains sorted.

As an aside thankyou very much for this package, dart deserves a quality immutable package and FIC seems to fill this role very nicely.

Metadata

Metadata

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions