@josevalim Can you provide a hint on how to do it more efficiently other than comparing the two lengths - just an idea or where to look to?
On Wednesday, February 21, 2024 at 12:21:56 PM UTC+1 José Valim wrote: > +1 for the proposal, but it has to be implemented more efficiently than > what was described here and we also need to add drop!. PRs welcome. > > On Wed, Feb 21, 2024 at 10:59 AM Artur Plysiuk <ifu...@gmail.com> wrote: > >> I just came here to add the same proposal. >> >> четвер, 28 грудня 2023 р. о 11:40:07 UTC+2 DaTrader пише: >> >>> It's not special at all. Actually it is as generic as the current >>> `Keyword.take/2`. You either want the operation to succeed if there aren't >>> all keys present or you want it to fail. Those are two equally important >>> use cases. >>> >>> On Thursday, December 28, 2023 at 3:21:50 AM UTC+1 rogers...@gmail.com >>> wrote: >>> >>>> I don't see such special use cases as good candidates to be included in >>>> builtins libraries. >>>> >>>> Em segunda-feira, 18 de dezembro de 2023 às 07:56:11 UTC-3, DaTrader >>>> escreveu: >>>> >>>>> Many times I need to merge a subset of a keyword list or a map into >>>>> another keyword list or map while requiring it to fail if not all keys >>>>> are >>>>> present. >>>>> >>>>> For this purpose I have small utility modules called KwUtils and >>>>> MapUtils where I have functions like the one below: >>>>> >>>>> ``` >>>>> @doc """ >>>>> Takes specified key-value pairs from the keyword list but raises if >>>>> any not found. >>>>> """ >>>>> @spec take!( keyword(), [ atom()]) :: keyword() >>>>> def take!( kw, keys) do >>>>> taken = Keyword.take( kw, keys) >>>>> >>>>> if length( taken) != length( keys) do >>>>> raise "Expected all keys in #{ inspect( keys)} to be present in >>>>> #{ inspect( kw)}" >>>>> end >>>>> >>>>> taken >>>>> end >>>>> ``` >>>>> >>>>> It'd be nice if a corresponding function was part of the `Keyword` and >>>>> `Map` modules each. >>>>> >>>>> -- >> 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/787ccf87-a103-4271-9d77-2101f1e23247n%40googlegroups.com >> >> <https://groups.google.com/d/msgid/elixir-lang-core/787ccf87-a103-4271-9d77-2101f1e23247n%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> > -- 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/5103d8c5-63a4-4844-9442-31d25b35d31an%40googlegroups.com.