首页 > 解决方案 > 我们如何在 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)> 

标签: typeselixir

解决方案


为什么你首先需要这个功能?Range是一个结构。我们在您可能需要的任何地方都有模式匹配。只需模式匹配就%Range{}可以了。


推荐阅读