diff --git a/lib/src/extensions/decode.dart b/lib/src/extensions/decode.dart index 65dc0e6..0a3be2c 100644 --- a/lib/src/extensions/decode.dart +++ b/lib/src/extensions/decode.dart @@ -62,7 +62,7 @@ extension _$Decode on QS { val = options.strictNullHandling ? null : ''; } else { key = options.decoder(part.substring(0, pos), charset: charset); - val = Utils.maybeMap( + val = Utils.apply( _parseArrayValue(part.substring(pos + 1), options), (dynamic val) => options.decoder(val, charset: charset), ); diff --git a/lib/src/extensions/encode.dart b/lib/src/extensions/encode.dart index 3fce227..2e1011b 100644 --- a/lib/src/extensions/encode.dart +++ b/lib/src/extensions/encode.dart @@ -59,7 +59,7 @@ extension _$Encode on QS { obj = serializeDate?.call(obj) ?? obj.toIso8601String(); } else if (generateArrayPrefix == ListFormat.comma.generator && obj is Iterable) { - obj = Utils.maybeMap( + obj = Utils.apply( obj, (value) => value is DateTime ? (serializeDate?.call(value) ?? value.toIso8601String()) @@ -93,7 +93,7 @@ extension _$Encode on QS { if (generateArrayPrefix == ListFormat.comma.generator && obj is Iterable) { // we need to join elements in if (encodeValuesOnly && encoder != null) { - obj = Utils.maybeMap(obj, encoder); + obj = Utils.apply(obj, encoder); } if ((obj as Iterable).isNotEmpty) { diff --git a/lib/src/utils.dart b/lib/src/utils.dart index f959fca..590d1db 100644 --- a/lib/src/utils.dart +++ b/lib/src/utils.dart @@ -408,7 +408,7 @@ final class Utils { if (b is Iterable) ...b else b, ]; - static dynamic maybeMap(dynamic val, T Function(T) fn) => + static dynamic apply(dynamic val, T Function(T) fn) => val is Iterable ? val.map((item) => fn(item)) : fn(val); static bool isNonNullishPrimitive(dynamic val, [bool skipNulls = false]) =>