Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Elixir ==的其他用法 #11

Open
zhulinpinyu opened this issue Dec 4, 2018 · 0 comments
Open

Elixir ==的其他用法 #11

zhulinpinyu opened this issue Dec 4, 2018 · 0 comments
Labels

Comments

@zhulinpinyu
Copy link
Owner

zhulinpinyu commented Dec 4, 2018

相等判断的基本用法

iex(3)> 2 == 2
true

另一种用法

iex(4)> Kernel.==(2, 2)
true

== 其实是Kernel内建的函数只是函数名有点怪。

参考代码

def is_valid_card(card_type, card_number) do
    case card_type do
      :debit ->
        card_number
        |> Integer.to_charlist()
        |> length
        |> Kernel.==(12)
       :credit ->
        card_number
        |> Integer.to_charlist()
        |> length
        |> Kernel.==(10)
       _ ->
        {:error, :invalid_card_type}
    end
end

https://medium.com/blackode/2-biggest-exunit-improvements-in-elixir-1-7-9116f7209c90

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant