With is_struct/2 coming in 1.11, I think it makes sense to add a guard for regexes at the same time.
It is rarely appropriate for Elixir developers to destructure a Regex struct: its implementation is semi-opaque (partially evidenced by the fact that it carries a version number <https://github.com/elixir-lang/elixir/blob/1145dc01680aab7094f8a6dbd38b65185e14adb4/lib/elixir/lib/regex.ex#L146-L148> with it). The main exception is trying to pattern match on function parameters to determine if input is a regex versus something else. MapSet is another example of a stdlib struct whose implementation is versioned <https://github.com/elixir-lang/elixir/blob/1145dc01680aab7094f8a6dbd38b65185e14adb4/lib/elixir/lib/map_set.ex#L57-L61>, and might make more sense to have a guard for rather than expecting developers to pattern match it for typecheck guards. However, since it is fully opaque, there are other problems implementing a guard for them, as discussed here already: https://groups.google.com/g/elixir-lang-core/c/2KnRcKTZvuE/m/229Nfw0oCwAJ The fact that a Regex is a struct is much more of an implementation detail than some other, raw-data stdlib structs; like Range, Date, Version, and URI. An is_regex/1 would help make that clearer, and prevent code like this <https://github.com/boydm/phoenix_markdown/blob/ef7b5f76f339babec688021080a70708d9ddf1c1/lib/phoenix_markdown/engine.ex#L80-L88> that has to choose between not using guards, or reaching into the struct implementation detail. considerations: - we'd want to re-implement Regex.regex?/1 in terms of it and possibly put that function into a deprecation path. - we'd need to remove it as an example in the guard Naming Convention <https://hexdocs.pm/elixir/naming-conventions.html#is_-prefix-is_foo> guide. - could be implemented in either Regex or Kernel. adding to Kernel sucks, but I think it would be a stronger commitment to the Regex struct implementation being an opaque detail. - it would make Regexs feel a lot more first-class Elixir data-typey, which they already do a lot just by virtue of inspecting as their sigil constructors. -- You received this message because you are subscribed to the Google Groups "elixir-lang-core" group. To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-core+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/071f08ea-f4cf-483e-bfe6-29d98af4bef7n%40googlegroups.com.