daml - 如何在 DAML 中按索引访问列表中的元素?
问题描述
假设一个列表的长度为三,我想访问第二个或中间元素。做这个的最好方式是什么?
解决方案
您可以为此使用列表索引运算符!!
,其定义如下:
(!!)
: [a] -> Int -> a
List index (subscript) operator, starting from 0.
这是一个演示其用法的片段:
first : [Int] -> Int
first x =
let f = x!!0
in f
testFirst = scenario do
assert(first [3, 2, 1] == 3)
推荐阅读
- r - 从坐标大数据集中获取时区的最快方法(一百万个坐标或更多)
- julia - 在 Julia 中绘制函数的运行时间
- c++ - 如何释放向量中的指针?
- ruby - Ruby:解析长字符串
- powershell - 使 Set-AzureStorageBlobContent 的选项不会覆盖 blob(如果已存在)
- android - 您将如何让用户选择在 WebView 应用程序中从他的本机浏览器打开 URL?
- javascript - 在 Cloud Function Firebase 中创建 GeoHash(用于 GeoFire)
- python - 如何在运动物体的轨迹中找到冗余路径(子路径)?
- android - 应用程序模块在 Android Studio 中消失
- swift - 快速控制流计数与倍数