Thanks for your replies,

yes, it could be an String.contains? analog:

[1,2,"3",4] |> Enum.join |> String.contains?("34")
[1,:a,"3",4] |> Enum.join |> String.contains?("a3")

About the recursive version, it seems to have best performance:

[image: image.png]

[image: image.png]

El vie, 15 jul 2022 a las 9:38, Aleksei Matiushkin (<
aleksei.matiush...@kantox.com>) escribió:

> I have not benchmarked it, but I believe the recursive approach would be
> better
>
> ```
> defmodule MyList do
>  def contains?(list, sublist, strict? \\ false)
>
>  def contains?(_, [], _), do: true
>  def contains?([], _, _), do: false
>  def contains?([h | t], [hh | _] = sub, strict?) when h != hh, do: not
> strict? and contains?(t, sub, strict?)
>  def contains?([h | t], [h | tt], strict?), do: contains?(t, tt, true) or
> contains?(t, [h | tt], strict?)
> end
> ```
>
> On Fri, Jul 15, 2022 at 2:07 PM 'eksperimental' via elixir-lang-core <
> elixir-lang-core@googlegroups.com> wrote:
>
>> Hi Julian.
>> It think it is a good addition.
>> It is also analog to String.contains?/2
>>
>> On Fri, 15 Jul 2022 04:58:59 -0700 (PDT)
>> Julian Somoza <
>> https://urldefense.proofpoint.com/v2/url?u=http-3A__julian.somoza-40gmail.com&d=DwICaQ&c=euGZstcaTDllvimEN8b7jXrwqOf-v5A_CdpgnVfiiMM&r=rmhwzhuTk1LyLPLZIrqkat6wS6r2qE3XZKnTTHGaxH8&m=rZfYwgMRyMdd1mpKac91VLHbd0qUJlcEVeNzbceWXvE&s=T8KKoaIf0UYlrJ_VQC1Qv_48Tje2jygIaQysVTXu2c0&e=>
>> wrote:
>>
>> > 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://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_elixir-2Dlang_elixir_pull_11987_commits_2b7eba5f6419f906f565e7d4bfe3d687f3b8b052&d=DwICaQ&c=euGZstcaTDllvimEN8b7jXrwqOf-v5A_CdpgnVfiiMM&r=rmhwzhuTk1LyLPLZIrqkat6wS6r2qE3XZKnTTHGaxH8&m=rZfYwgMRyMdd1mpKac91VLHbd0qUJlcEVeNzbceWXvE&s=rqpOP9kyNDkOSBV-I2zlHssI6EVLQQ-iBW1F0k3nqFg&e=
>> >
>> > 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://urldefense.proofpoint.com/v2/url?u=https-3A__groups.google.com_d_msgid_elixir-2Dlang-2Dcore_62d1588e.1c69fb81.3332c.1d2dSMTPIN-5FADDED-5FMISSING-2540gmr-2Dmx.google.com&d=DwICaQ&c=euGZstcaTDllvimEN8b7jXrwqOf-v5A_CdpgnVfiiMM&r=rmhwzhuTk1LyLPLZIrqkat6wS6r2qE3XZKnTTHGaxH8&m=rZfYwgMRyMdd1mpKac91VLHbd0qUJlcEVeNzbceWXvE&s=Ckh5t8xdml-Vx3UgfKMNxh3CoSb8IBfBORyYgVxcXsg&e=
>> .
>>
>
>
> --
> *Aleksei Matiushkin*, Software Engineer - R&D
>
> Office (+34) 935 679 834
>
>
>
> 8 Devonshire Square, London, EC2M 4PL, United Kingdom
> Torre Mapfre, Planta 22, Marina, 16-18, 08005 Barcelona, Spain
> *kantox.com <http://kantox.com/>*
>
>
>
>
>
>
>
>
>
>
> <http://www.linkedin.com/company/1871617>
> <http://www.linkedin.com/company/1871617>[image: LinkedIn]
> <https://www.linkedin.com/company/1871617>
> <https://twitter.com/kantox>[image: Twitter] <https://twitter.com/kantox>
>    <http://www.youtube.com/user/kantoxfx>[image: YouTube]
> <https://www.youtube.com/user/kantoxfx>
>
> Kantox Limited is a UK private company with registered company number
> 07657495 and registered address at 8 Devonshire Square, London EC2M 4PL,
> United Kingdom. We are authorised with the UK Financial Conduct Authority
> (FCA) under the Payment Service Regulation 2017 as a Payments Institution
> (FRN 580343) for the provision of payment services and with HMRC as a Money
> Service Business Registration No.12641987.
> Kantox European Union, S.L.  is a Spanish private company with tax ID
> number B67369371 and registered address at Torre Mapfre, Planta 22, Marina,
> 16-18, 08005 Barcelona, Spain. Kantox is authorized by the Bank of Spain,
> with registration number 6890, which is the supervisor of the Spanish
> banking system along with the European Central Bank. Additionally, we are
> supervised by SEPBLAC, the Supervisory Authority for the prevention of
> money laundering and terrorist financing in Spain.
> KANTOX is the Controller for the processing of data in accordance with the
> GDPR and LOPDGDD for the purpose of maintaining a commercial relationship.
> You may exercise your rights of access and rectification, portability,
> restriction and opposition by writing to KANTOX to the email:
> g...@kantox.com. You have your right to make a complaint at www.aepd.es.
>
> --
> 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/CAGF5_6efo17fReu7sLXYxAO_%3DBdSiPFRSuf_Y1MiKNt1owsoYw%40mail.gmail.com
> <https://groups.google.com/d/msgid/elixir-lang-core/CAGF5_6efo17fReu7sLXYxAO_%3DBdSiPFRSuf_Y1MiKNt1owsoYw%40mail.gmail.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/CACFi_YOGbfSBn4jYJ4djPwVeuwxYu0cWt5Mja62f%3DWmZKZ7CUQ%40mail.gmail.com.

Reply via email to