--
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-co...@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.
Thank you for the useful feedback! Let me try addressing your excellent points in turn:
From: <elixir-l...@googlegroups.com> on behalf of Sabiwara Yukichi <sabi...@gmail.com>
Reply-To: "elixir-l...@googlegroups.com" <elixir-l...@googlegroups.com>
Date: Tuesday, December 13, 2022 at 6:55 PM
To: "elixir-l...@googlegroups.com" <elixir-l...@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.
To view this discussion on the web visit
https://groups.google.com/d/msgid/elixir-lang-core/CANnyohYy8hRvu2WD%2BMUEzWS2SxoA8eYk9PETOe8jGxr2tiuW%2BA%40mail.gmail.com.
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 pri...@covermymeds.com. Thank you.
Cool yeah – I think extending the contexts in which we can use pattern matching is a good idea generally. So your `destructure/4` would let us pull out any number of data points from a structure and do some work on them and return them. Very cool! Hmmm maybe it shouldn’t be “destructure” anymore but “restructure”.
I think it’d be somewhat verbose for the use cases I had in mind for `pattern_filter`, but would make for a nice new way to pattern match!
To view this discussion on the web visit
https://groups.google.com/d/msgid/elixir-lang-core/4cdeeb01-0446-4385-bea5-062476cc76c2n%40googlegroups.com.
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-l...@googlegroups.com> on behalf of Sabiwara Yukichi <sabi...@gmail.com>
Reply-To: "elixir-l...@googlegroups.com" <elixir-l...@googlegroups.com>
Date: Tuesday, December 13, 2022 at 6:55 PM
To: "elixir-l...@googlegroups.com" <elixir-l...@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):
To view this discussion on the web visit
https://groups.google.com/d/msgid/elixir-lang-core/CANnyohYy8hRvu2WD%2BMUEzWS2SxoA8eYk9PETOe8jGxr2tiuW%2BA%40mail.gmail.com.
Hi Ben,
Thank you for the feedback!
The pattern_filter requires a pattern with exactly one variable and therefore always returns just the value bound to that variable.
```
{1, 2, 3} |> pattern_filter({1, a, b})
```
would result in an ArgumentError, but
```
{1, 2, 3} |> pattern_filter({1, _a, b})
# 3
# or
{1, 2, 3} |> pattern_filter({1, a, _})
# 2
# would both work
```
The shape of the return is stereotyped, so it is simpler than `then`.
I will put the code up on github and share!
Thanks,
Matt F
From: <elixir-l...@googlegroups.com> on behalf of Ben Wilson <benwil...@gmail.com>
Reply-To: "elixir-l...@googlegroups.com" <elixir-l...@googlegroups.com>
Date: Thursday, December 15, 2022 at 4:12 PM
To: elixir-lang-core <elixir-l...@googlegroups.com>
To view this discussion on the web visit
https://groups.google.com/d/msgid/elixir-lang-core/b0bcc5d3-0eb0-4ee4-9309-d9e8cccf972cn%40googlegroups.com.
Hi Ben,
I agree that it reduces its applicability, but I see that as a virtue. Filter and Map are useful despite being less applicable than Reduce, since they are simpler.
Matt F
From: <elixir-l...@googlegroups.com> on behalf of Ben Wilson <benwil...@gmail.com>
Reply-To: "elixir-l...@googlegroups.com" <elixir-l...@googlegroups.com>
Date: Thursday, December 15, 2022 at 4:23 PM
To: elixir-lang-core <elixir-l...@googlegroups.com>
To view this discussion on the web visit
https://groups.google.com/d/msgid/elixir-lang-core/a3878ce0-397a-4a42-86db-12f475d4498an%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/9DE6BF24-8902-45DA-8BC1-687037D4466A%40covermymeds.com.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-core+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/a3878ce0-397a-4a42-86db-12f475d4498an%40googlegroups.com.
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 privacy@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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/9DE6BF24-8902-45DA-8BC1-687037D4466A%40covermymeds.com.
--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/CAGnRm4KzqaLTtDKEz_rBx7W5waHao%3Dm9JMGJn%2BJ0Z9OeHMLW6w%40mail.gmail.com.
Thanks for the reply, José. I was thinking that more ways to pattern match is a good thing. I’m still new to the language so I might not have its philosophy internalized yet.
I probably should have included at least the heads of the macros:
defmacro pattern_filter(value, pattern, default \\ nil)
defmacro pattern_filter!(value, pattern)
So the fallback can be specified as not nil. One of my examples returns “???” when not matching. I was just trying to make it like `Map.get` in that sense. So your example would become this:
case res do
{:ok, value} -> value
:error -> :default
end
|> pattern_filter({:ok, value}, :default)
I agree that it is less flexible than a case – maybe more akin to a ternary with a pattern.
I also think that if you needed to extract two variables, then pattern_filter wouldn’t be the right tool.
In any case, I really appreciate how much thoughtful feedback I gained from you and the others who replied! I’m glad to be working in Elixir.
To view this discussion on the web visit
https://groups.google.com/d/msgid/elixir-lang-core/CAGnRm4KzqaLTtDKEz_rBx7W5waHao%3Dm9JMGJn%2BJ0Z9OeHMLW6w%40mail.gmail.com.