types - 我们如何在 Elixir 中测试“范围”类型
问题描述
我们如何测试一个Range
类型?相当于is_range
什么?
Erlang/OTP 21 [erts-10.1] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1]
Interactive Elixir (1.7.3) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> a = 1..10
1..10
iex(2)> is_list a
false
iex(3)> i a
Term
1..10
Data type
Range
Description
This is a struct. Structs are maps with a __struct__ key.
Reference modules
Range, Map
Implemented protocols
IEx.Info, Enumerable, Inspect
iex(4)>
解决方案
为什么你首先需要这个功能?Range
是一个结构。我们在您可能需要的任何地方都有模式匹配。只需模式匹配就%Range{}
可以了。
推荐阅读
- sql - 网络适配器无法建立连接 (Oracle)
- java - 限制通用向上转换
- html - 乳胶 \textbackslash 不起作用,rmarkdown html
- java - 如何将数据添加到Java中另一个类的数组中?
- rust - 有没有办法用 Serde 定义标签字段?
- c# - 非静态字段、方法或属性“Flashlight.character”需要对象引用
- java - 关于编译器评估顺序的代码说明
- extract - Mathematica Manipulate:如何提取局部变量的值?
- c# - 使用 SqlDataReader 使条件正确?
- python - Matplotlib 图像未出现在 Visual Studio Code 中