Hi again. I’m new to this so apologies if I’m coming off as clueless or pushy. I’m wondering what, if any, next steps there are to advocate for this. Should I share the code? Given what I mentioned in the responses about using one variable or using a new `destructure`, is there still disagreement?
Thanks! Matt F From: <elixir-lang-core@googlegroups.com> on behalf of Sabiwara Yukichi <sabiw...@gmail.com> Reply-To: "elixir-lang-core@googlegroups.com" <elixir-lang-core@googlegroups.com> Date: Tuesday, December 13, 2022 at 6:55 PM To: "elixir-lang-core@googlegroups.com" <elixir-lang-core@googlegroups.com> Subject: [EXTERNAL] Re: [elixir-core:11213] [proposal] Use patterns to filter data (good for pipes) This email came from a source outside of CoverMyMeds. Use caution when clicking on links or replying with confidential information. ________________________________ This is an interesting idea, but maybe `then/2` (or case/2 if you're fine piping in it) could already cover these cases quite well (equivalent to your pattern_filter! function): "$3.45" |> then(fn "$" <> money -> money end) |> String.to_float() "$3.45" |> case do "$" <> money -> money end |> String.to_float() The non-raising alternative might be slightly more verbose because you need a second clause. But most of the time (like your money example), the next step of the pipe might fail on nil anyway. Or maybe a with/1 pipeline might work better than the pipe operator if you want a succession of happy-path matches? If we move forward, it might be better to explicitly declare the returned expression, not just infer it from dangling variables: it isn't obvious what should `{a, b}` or `{a, b, a}` return. Something like: {1, 2, 1} |> pattern_filter(b <- {a, b, a}) Le mer. 14 déc. 2022 à 05:50, 'Matt Farabaugh' via elixir-lang-core <elixir-lang-core@googlegroups.com<mailto:elixir-lang-core@googlegroups.com>> a écrit : All, I wrote a macro which allows for using a pattern to essentially extract a value from a data structure: @doc """ Filter a value out of data using a pattern with one variable. Returns a default value if no match. Raises if pattern contains no variables or more than one variable. ## Examples iex> "$3.45" |> PatternHelpers.pattern_filter("$" <> money) |> String.to_float() 3.45 iex> {1,2,3} |> PatternHelpers.pattern_filter({1,_,a}) 3 iex> %{a: 1, b: 2} |> PatternHelpers.pattern_filter(%{a: 9, b: b}) nil iex> %{a: 1, b: 2} |> PatternHelpers.pattern_filter(%{a: 9, b: b}, "???") "???" """ And an unsafe version: @doc """ See `pattern_filter/3`. Raises if no match. ## Examples iex> {1,2,3} |> PatternHelpers.pattern_filter!({9,_,b}) ** (MatchError) no match of right hand side value: {1, 2, 3} """ This is my first proposal. Please let me know if this idea is worth some attention, and how I might better do my part to present it. I have code obviously but I'm not sure this is the place for it. Thanks, Matt F -- 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<mailto:elixir-lang-core+unsubscr...@googlegroups.com>. To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/4b65083e-6c36-4519-a0ed-fa2da8b61a9bn%40googlegroups.com<https://urldefense.com/v3/__https:/groups.google.com/d/msgid/elixir-lang-core/4b65083e-6c36-4519-a0ed-fa2da8b61a9bn*40googlegroups.com?utm_medium=email&utm_source=footer__;JQ!!LBRzLL-rxcoG!soAu7_j204hUseqlxMsemQMOhOz0yO8WygSZdV2t7WGq5iDQfDh-prkOc8PkTmo4vz08vKeE_ZmAZ19k2vMrPomauA$>. -- 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<mailto:elixir-lang-core+unsubscr...@googlegroups.com>. To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/CANnyohYy8hRvu2WD%2BMUEzWS2SxoA8eYk9PETOe8jGxr2tiuW%2BA%40mail.gmail.com<https://urldefense.com/v3/__https:/groups.google.com/d/msgid/elixir-lang-core/CANnyohYy8hRvu2WD*2BMUEzWS2SxoA8eYk9PETOe8jGxr2tiuW*2BA*40mail.gmail.com?utm_medium=email&utm_source=footer__;JSUl!!LBRzLL-rxcoG!soAu7_j204hUseqlxMsemQMOhOz0yO8WygSZdV2t7WGq5iDQfDh-prkOc8PkTmo4vz08vKeE_ZmAZ19k2vMQT4CMDA$>. This electronic transmission is confidential and intended solely for the addressee(s). If you are not an intended addressee, do not disclose, copy or take any other action in reliance on this transmission. If you have received this transmission in error, please delete it from your system and notify CoverMyMeds LLC at priv...@covermymeds.com. Thank you. -- 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/53A15DB8-B2E6-409D-98DB-B7E92A0D0116%40covermymeds.com.