About patterns with typed data

I have a difficulty to define the pattern to obtain this result:

Function[TypedData[{{1,2}, 2, {2,3,4}}] = True

Function[TypedData[{{1,2}, 2, {2,3,4}}], TypedData[{{a, 1}, d, 1}]]= True


Here what I m trying :

Function[TypedData[{_list,_,_list}]__] := True


I put a BlankSequence after my TypedData because I wanted my function answers True if I have 1 or several TypedData but I doesn’t work.

May you help me to define a good pattern which can work with the TypedData ?

Thank you for your help.

• Have you tried it with List instead of list? Also you probably want .. at the end of the pattern instead of __. And the blank in the middle insists on a middle expression, so three expressions inside TypedData, with lists at the beginning and end. Is that what you want? Aug 8, 2021 at 15:02
• i think you are completely right about the .. but i need also a blanksequence to ask Mathematica that i can have 1 or several typed Data. Indeed, Typed data is composed of list of 3 expressions Aug 8, 2021 at 15:16
• @Michael E2 OK. it woks but i didn't understand why ".." can replace "__". How i have been able to do if have wanted 0, 1 or several typed Data in my case ? Aug 8, 2021 at 15:20
• Function[TypedData[{_List, _, _List}]..] := True may be the answer. It seems to be a mistake that in your original expression there is only a left brace. It's a syntax error. Aug 8, 2021 at 15:26
• @MichaelE2 a remind so that you can see my question. Thank you for your help. Aug 8, 2021 at 15:26

1 Answer

ClearAll["Global*"]


Note that it is generally not a good idea to begin user-defined symbols with a capital letter since this could give rise to naming conflicts with built-in names. Perhaps what you intend is

typedDataQ[{_List, _Integer, _List} ..] := True


Note that if the middle argument is not intended to be an Integer just use _ or perhaps some other Head such as Real or Rational or String

Then to handle all other arguments

typedDataQ[___] := False


Testing valid data

typedDataQ[{{1, 2}, 2, {2, 3, 4}}]

(* True *)


Testing invalid data

typedDataQ[{3, 2, {2, 3, 4}}]

(* False *)


Testing multiple valid data

typedDataQ[{{1, 2}, 2, {2, 3, 4}}, {{6, 9, 6, 8}, 2, {1, 8, 2}}]

(* True *)


Testing mix of valid and invalid data

typedDataQ[{{1, 2}, 2, {2, 3, 4}}, {{6, 9, 6, 8}, 2, 7}]

(* False *)


Testing mix, item-by-item

typedDataQ /@ {{{1, 2}, 2, {2, 3, 4}}, {{6, 9, 6, 8}, 2, 7}}

(* {True, False} *)

• Thank you ! You perfectly answer to my question Aug 8, 2021 at 15:39
• Note also that _List covers a wide variety of structures. Depending on the application, you might want a tighter restriction such as _?VectorQ` Aug 8, 2021 at 16:01
• in fact it was not what I expected. I answered to quickly. I wanted the repeated .. after the TypedData and that is to say after the closing bracket Aug 8, 2021 at 19:28
• may you have a look at my comment ? Aug 8, 2021 at 19:29
• Your comment makes no sense to me. Don't tell us how to code, tell us how you want the code to perform. Provide examples of input for which the provided code does not do as you expect and tell us the result that you want instead. I will be away from my computer for 8 or 9 hours. Aug 8, 2021 at 19:42