# Get matching types for pattern

I want to take a pattern and get a set of matching types. The set of types does not need to be complete, but it needs to satisfy, say, 90% of the cases.

Here's is a (definitely not complete) set of examples:

arg_ -> "Arbitrary"
arg__ -> "Arbitrary sequence"
arg___ -> "Arbitrary blank sequence"
a_?IntegerQ -> "Integer"
b_Real -> "Real number"
b_Real?InternalRealValuedNumericQ -> "Real number"
b_?(Not@*IntegerQ) :> "Arbitrary non-integer"
b_?randomTest ->
If[MatchQ[randomTest, Symbol],
"Arbitrary object passing randomTest",
"Indeterminate"
]
b_?(Not@*randomTest) :> "Arbitrary object failing randomTest"
OptionsPattern[] -> "Options"
ops : OptionsPattern[] -> "Options"


Being able to spelunk like this will allow me to automatically generate more useful documentation than the trash I generate right now. Even better, we can finally document lots of WRIs trash in a useful way. Bonus points if you can take this and extend it to return a reasonable example a user could execute to get a sense for what the function does.

### Hints:

TypeSystem\$AtomPattern

HoldPattern[
Integer | Real | String | TypeSystemBoolean | Rational |
TypeSystemEnumeration[__String] | DateObject | TimeObject |
TemporalData | Image |
Entity[_String] | _Quantity?TypeSystemValidQuantityQ |
GeoPosition | Graph | Graphics | GeoGraphics | Sound | CloudObject |
File | URL | Hyperlink | IPAddress | HTTPResponse | HTTPRequest |
TypeSystemAnyType]

• So "set of matching types" is a list of strings from examples shown above? – Kuba Jan 20 '19 at 13:00
• " Even better, we can finally document lots of WRIs trash in a useful way." If I didn't know better I'd be inclined to downvote for that remark. (Something I rarely do by the way.) – Daniel Lichtblau Jan 20 '19 at 15:26
• @DanielLichtblau "WRI's trash" is obviously a reference to highly useful undocumented functions :) But if the line grates I can rewrite it in somewhat more polite language. – b3m2a1 Jan 20 '19 at 19:17
• Somehow "useful" and "trash" don't seem to go together (then again, neither do "useful" and "idiot" and yet they have been paired in a colloquialism for some time now). . On a different but related note, we have begun on the Wolfram Function Repository, and some functions from the GeneralUtilities context are being added there. The advantage is they then get better user-visible documentation. – Daniel Lichtblau Jan 21 '19 at 15:51
• What I meant about the repo was not necessarily that you should contribute (though of course we would welcome that) but rather that some of the undocumented "stuff" you have in mind will now be better documented. – Daniel Lichtblau Jan 21 '19 at 22:25