Hi everyone, I was working on a suggestion to add a new function on the List module in order to find out if a given sublist is inside another list.
We currently have *List.starts_with?/2* but this only match the beginning: iex(1)> List.starts_with?([1, 2, 3], [1, 2]) true Besides, we have *MapSet.subset*, but it ignores the elements order: iex(1)> MapSet.subset?(MapSet.new([1, 2]), MapSet.new([1, 2, 3])) true iex(1)> MapSet.subset?(MapSet.new([2, 1]), MapSet.new([1, 2, 3])) true I suggest a new function that works like *List.starts_with?/2* but matches the entire list, either at the beginning, middle, or end of the list. iex(1)> List.includes_sublist?([1,2,3,4,5], [2,3]) true iex(1)> List.includes_sublist?([1,2,3,4,5], [1,2]) true iex(1)> List.includes_sublist?([1,2,3,4,5], [3,4,5]) true iex(1)> List2.includes_sublist?([1,2,3,4,5], [1,5]) false I'm sharing with you also the function code: https://github.com/elixir-lang/elixir/pull/11987/commits/2b7eba5f6419f906f565e7d4bfe3d687f3b8b052 I aim to complement the List.starts_with?/2. This function could be the same or even more useful because it finds the ordered sublist also in the middle or in the end. Looking forward for your comments, BR, Julian Somoza. -- 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/cc00d3fc-34ec-43bb-84c2-885311f4507an%40googlegroups.com.