when<T> method

T when<T>({
  1. required T rectangle(
    1. DownloadableRegion<RectangleRegion> rectangle
    ),
  2. required T circle(
    1. DownloadableRegion<CircleRegion> circle
    ),
  3. required T line(
    1. DownloadableRegion<LineRegion> line
    ),
  4. required T customPolygon(
    1. DownloadableRegion<CustomPolygonRegion> customPolygon
    ),
})

Output a value of type T dependent on originalRegion and its type R

Implementation

T when<T>({
  required T Function(DownloadableRegion<RectangleRegion> rectangle)
      rectangle,
  required T Function(DownloadableRegion<CircleRegion> circle) circle,
  required T Function(DownloadableRegion<LineRegion> line) line,
  required T Function(DownloadableRegion<CustomPolygonRegion> customPolygon)
      customPolygon,
}) =>
    switch (originalRegion) {
      RectangleRegion() => rectangle(_cast()),
      CircleRegion() => circle(_cast()),
      LineRegion() => line(_cast()),
      CustomPolygonRegion() => customPolygon(_cast()),
    };