一天熟悉Elixir,练习Koans

最近在exercism.io练习,那个难度稍微大一些,大概要一个月吧,适合于做第二阶段提高的练习。

今天发现一个新的不错的初学练习方式,一天就能熟悉Elixir的一些基础,一共18关。

第一关

比如,第一个简单地判断相等:

defmodule Equalities do
  use Koans

  @intro  """
  Welcome to the Elixir koans.
  Let these be your first humble steps towards learning a new language.

  The path laid in front of you is one of many.
  """

  # Replace ___ with the answer to make the koan pass.
  koan "We shall contemplate truth by testing reality, via equality" do
    assert true == ___
  end

  koan "Not something is the opposite of it" do
    assert !true == ___
  end

  koan "To understand reality, we must compare our expectations against reality" do
    assert 2 == 1 + ___
  end

  koan "Some things may appear different, but be the same" do
    assert 1 == 2 / ___
  end

  koan "Unless they actually are different" do
    assert 3.2 != ___
  end

  koan "Some may be looking for bigger things" do
    assert ___ > 3
  end

  koan "Others are happy with less" do
    assert ___ < 3
  end
end

所有的题目

01_equalities.ex       07_lists.ex            13_functions.ex
02_strings.ex          08_keyword_lists.ex    14_enums.ex
03_sigils.ex           09_maps.ex             15_processes.ex
04_numbers.ex          10_map_sets.ex         16_tasks.ex
05_atoms.ex            11_structs.ex          17_agents.ex
06_tuples.ex           12_pattern_matching.ex 18_protocols.ex

后面4个稍微陌生和难一点。

运行方式

mix deps.get

mix meditate

不断练习

可以反复练习直到这些成为直觉。

项目学习

这个Koans本身是个不错的学习项目,可以通过它学习到一个完整的项目是如何建构的。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值