Elixir语言中 Kernel.unless
相关用法介绍如下。
用法:
unless(condition, clauses)
(宏)
提供unless
宏。
如果 condition
的计算结果为假值( false
或 nil
),此宏计算并返回作为第二个参数传入的 do
块。否则,它返回else
块的值(如果存在)或nil
(如果不存在)。
另见
。if/2
例子
iex> unless(Enum.empty?([]), do: "Hello")
nil
iex> unless(Enum.empty?([1, 2, 3]), do: "Hello")
"Hello"
iex> unless Enum.sum([2, 2]) == 5 do
...> "Math still works"
...> else
...> "Math is broken"
...> end
"Math still works"
相关用法
- Elixir Kernel.update_in用法及代码示例
- Elixir Kernel.use用法及代码示例
- Elixir Kernel.SpecialForms.case用法及代码示例
- Elixir Kernel.round用法及代码示例
- Elixir Kernel.left / right用法及代码示例
- Elixir Kernel.put_in用法及代码示例
- Elixir Kernel.tl用法及代码示例
- Elixir Kernel.left - right用法及代码示例
- Elixir Kernel.tuple_size用法及代码示例
- Elixir Kernel.defexception用法及代码示例
- Elixir Kernel.to_charlist用法及代码示例
- Elixir Kernel.base ** exponent用法及代码示例
- Elixir Kernel.left !== right用法及代码示例
- Elixir Kernel.if用法及代码示例
- Elixir Kernel.spawn_monitor用法及代码示例
- Elixir Kernel.to_string用法及代码示例
- Elixir Kernel.length用法及代码示例
- Elixir Kernel.first..last用法及代码示例
- Elixir Kernel.SpecialForms.%{}用法及代码示例
- Elixir Kernel.SpecialForms.for用法及代码示例
- Elixir Kernel.then用法及代码示例
- Elixir Kernel.spawn用法及代码示例
- Elixir Kernel.defmodule用法及代码示例
- Elixir Kernel.SpecialForms.quote用法及代码示例
- Elixir Kernel.left > right用法及代码示例
注:本文由纯净天空筛选整理自elixir-lang.org大神的英文原创作品 Kernel.unless(condition, clauses)。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。