From e83e99758a1d8397686b35cb3c3b51f6c962971e Mon Sep 17 00:00:00 2001 From: Simon Diesenreiter Date: Fri, 13 Dec 2024 13:13:43 +0100 Subject: [PATCH] feat: add filter option to TokenConverter, ref: NOISSUE --- TextParser/Data/DataManipulationHelpers.cs | 20 ++++++++++++++++++++ TextParser/Data/TokenConverter.cs | 17 +++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/TextParser/Data/DataManipulationHelpers.cs b/TextParser/Data/DataManipulationHelpers.cs index 68218a2..408a39c 100644 --- a/TextParser/Data/DataManipulationHelpers.cs +++ b/TextParser/Data/DataManipulationHelpers.cs @@ -20,4 +20,24 @@ public static class DataManipulationHelpers { return reducer(data); } + + public static List TransformData(this List data, Func transformer) + { + var newList = new List(); + foreach (TType dataItem in data) + { + newList.Add(transformer(dataItem)); + } + return newList; + } + + public static List TransformData(this List> data, Func, TNewType> transformer) + { + var newList = new List(); + foreach (List dataItemList in data) + { + newList.Add(transformer(dataItem)); + } + return newList; + } } \ No newline at end of file diff --git a/TextParser/Data/TokenConverter.cs b/TextParser/Data/TokenConverter.cs index 5cd7fe4..33f5753 100644 --- a/TextParser/Data/TokenConverter.cs +++ b/TextParser/Data/TokenConverter.cs @@ -156,4 +156,21 @@ public class TokenConverter return newList; } + + public TokenConverter Filter(params InputType[] inputTypes) + { + var newTokenList = new List>() + + foreach(var token in rawTokens) + { + if(inputTypes.Contains(token.GetInputType())) + { + newTokenList.Add(token); + } + } + + this.rawTokens = newTokenList; + + return this; + } }