竹林品雨

业精于勤荒于嬉,行成于思毁于随

Pattern Matching 精进 & Pin 操作符

Elixir

Variables Bind Once (per Match) 模式匹配中,同一变量只能有一次匹配值绑定,否侧报错 iex(1)> [a,a] = [1,1] # [1, 1] iex(2)> a # 1 iex(3)> [b,b] = [1,2] # ** (MatchError) no match of right hand side value: [1, 2] ...

mix 自定义Task

Elixir

Thanks: http://elixirschool.com/lessons/basics/mix-tasks/ 创建Project, 命名为custom_mix_task mix new custom_mix_task 添加一个函数为lib/custom_mix_task.ex defmodule CustomMixTask do @doc """ Output's ...

Elixir 使用 ex_doc 将注释生成文档

依赖库:ex_doc 生成module的文档: 在module中添加文档注释 defmodule Cards do @moduledoc """ Provide some methods for handing deck. 这是一些随便的注释 运行 mix docs就会生成 doc/index.html """ def create_deck do .....

Elixir Test概览

Thanks: http://elixirschool.com/cn/lessons/basics/testing/ 在根目录下运行测试: mix test 另:同时doctest 也可以 自动测试method注释中的示例 比如 @doc """ return two part, one is hand specific by count argument ## Example ...

Elixir 的Sigils 小波浪线`~`

Thanks: http://elixirschool.com/lessons/basics/sigils/ 其作用就是实现对字面量的转义。 以下Sigils 大写表示原样输出,小写表示计算后输出 Char List ~c 和~C iex(7)> ~c/2 + 7 = #{2 + 7}/ '2 + 7 = 9' iex(8)> ~C/2 + 7 = #{2 + 7}/ '...

Elixir Module and Struct概览

updated: 2016-12-19, 2017-07-24 Thanks: http://elixirschool.com/cn/lessons/basics/modules/ 模块(Module)的属性 defmodule Example do @reeting "Hello" def greeting(name) do ~s(Ok, #{@reeting} #...