How come this particular string filtering does not work in Elixir?

StackOverflow https://stackoverflow.com/questions/22278532

  •  11-06-2023
  •  | 
  •  

سؤال

Why does this work:

iex(9)> Enum.filter(["lowks", "kian", "seong"], fn(x) -> x == "lowks" end)
["lowks"]

While this does not:

iex(5)> Enum.filter(String.split("low kian seong"), fn(x) -> x == "lowks" end) []

Is it because I am filtering the function ?

هل كانت مفيدة؟

المحلول

Unless I'm missing something, you have a typo in the second example. It should be lowks not low.

iex(1)> Enum.filter(String.split("lowks kian seong"), fn(x) -> x == "lowks" end)
["lowks"]
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top