具有默认参数的函数的Elixir类型规范 [英] Elixir type spec for a function with default parameters

查看:53
本文介绍了具有默认参数的函数的Elixir类型规范的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何为接受一个具有默认值的参数的函数编写类型规范?类似于以下内容:

How do I write a type spec for the function that accepts, let's say, one parameter which has a default value? Something like the following:

def foo(bar \\ 10) do
  bar
end

会是这样吗

@spec foo(integer) :: integer

那会是什么?

谢谢.

推荐答案

是.

我要补充一点,如果您的问题是具有默认值的参数的函数的类型规范与没有默认值的函数的类型规范之间是否存在差异,那么就没有区别了.

I would add that if your question is if there is a difference between the typespec of a function which has an argument with a default value and an argument that doesn't, then no there is no difference.

这篇关于具有默认参数的函数的Elixir类型规范的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆