The idea is to normalize a string before processing it to extract information from it. Strings may come with embedded outer brackets which are easily stripped or as elements of a true list. This is early in the development of parse
but I just cannot figure out why it works fine with pure strings but fails when given in a list. It's not like I haven't worked much with Lists before. I'm now toward end of year 2 in experience with MMA. But other than labels and similar constructs I really have not done anything with strings considered intermediate or advanced.
Below is my nearly nude parse. In comments above it are things i tried but failed.
(* LabeledEcho 0.5.0 utilities: parse *)
ClearAll[LabeledEcho,parse];
ClearSystemCache[]
(* other things attempted on True *)
(* condition to lift out the string *)
(* Take[str,{1,-1}] *)
(* First@str *)
(* Identity@@str *)
(* Replace[str,List->Identity] *)
(* Replace[str,List->Sequence] *)
parse[str : _String | List] := With[{
expr = If[ListQ@str, Sequence @@ str, str]
},
cln = If[StringFreeQ[expr, {"{", ",", "}", Whitespace}],
Return[expr], StringDelete[expr, {"{", "}"}]];
Echo[ cln, "cln \[Rule] "]
];
string = "{ABC,Its,easy,as,123},{as simple as Do re mi}, ABC, \
123,{Baby you and me girl, }";
Head@string
str = parse[string]
list = {"{ABC,Its,easy,as,123},{as simple as Do re mi}, ABC, \
123,{Baby you and me girl, }"};
Head@list
lst = parse[list]
parse[str : _String | _List]
instead ofparse[str : _String | List]
(note the second underscore). $\endgroup$lst = parse[First@list]
but @Domen's answer is canonical and I will go with that.. $\endgroup$parse[str : _String | {_String ..}]
should do it. $\endgroup$