From 790631427ee3cde68a25486baef0508f52b32993 Mon Sep 17 00:00:00 2001 From: Robbendebiene Date: Mon, 19 Jun 2023 12:36:02 +0200 Subject: [PATCH] Minor expression improvements --- lib/models/expression_handler.dart | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/models/expression_handler.dart b/lib/models/expression_handler.dart index c3b128fb..1bf635f9 100644 --- a/lib/models/expression_handler.dart +++ b/lib/models/expression_handler.dart @@ -6,7 +6,7 @@ typedef SubstitutionCallback = Iterable Function(String variableName); /// Expressions must not throw an error. /// Instead they return a meaningful result if possible or null. -typedef Expression = String? Function(Iterable); +typedef ExpressionCallback = String? Function(Iterable); /// A utility class that can be mixed in to get expression support wherever needed. @@ -33,7 +33,7 @@ mixin ExpressionHandler { /// A name to function mapping for expressions. - static const _expressionMapping = { + static const _expressionMapping = { 'JOIN': _join, 'CONCAT': _concat, 'COALESCE': _coalesce, @@ -51,7 +51,7 @@ mixin ExpressionHandler { } final expressionIdentifier = rawExpression.first; - final Expression? expression; + final ExpressionCallback? expression; final Iterable parameters; if (expressionIdentifier is! String || expressionIdentifier.isEmpty) { @@ -99,18 +99,21 @@ mixin ExpressionHandler { // expression functions String? _join(Iterable args) { - if (args.isEmpty) { - return null; - } + if (args.isEmpty) return null; + final delimiter = args.first; final values = args.skip(1); return values.isEmpty ? null : values.join(delimiter); } +/// Returns the concatenation of all inputs. + String? _concat(Iterable args) { return args.isEmpty ? null : args.join(); } +/// Returns the first input and discards the others. + String? _coalesce(Iterable args) { return args.isEmpty ? null : args.first; }