Notice
Recent Posts
Recent Comments
Link
«   2025/05   »
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
Archives
Today
Total
관리 메뉴

psj2867

elixir cheat sheet 본문

언어/elixir

elixir cheat sheet

psj2867 2022. 10. 7. 15:03

--type - tuple / list / map
tuple = {1,2,3}
list = [1,2,3,,]
map = %{} || %{ a => b }
atom map = %{a: b }
#not sorted, unique, {atom, value}
** %{ map | key: value ,,}
keyword list = [key: value,,,] || [{:key, value},,]
#sorted, not unique, {atom,value}

defmodule m1 do
    defstruct a: nil, b:nil
end
%m1{a: b}

--literal
bytes = <<>> || <<n>> ( n % 256) || <<n::bit-size>>
** b1 <> b2
string = "#{var1}"

--sigils
string = ~s()
string without backslash = ~S()
date = ~D[YYYY-MM-DD]
naive_date = ~N[]
time = ~T[]

--fn
a = fn x -> x end
a = fn 
    x -> x 
    x,y -> x,y
    end
a = &f1/n || &(&1)

def f1(a, b \\ default , opt \\ [] ) 

--op
== -> true/false
&& -> value


--module
alias a.b.c //(c)
alias a.b.c, as: d //(d)
alias a.{b,c}

import a //a.*
impotr a, only: [f1: arity], except: [f1: arity]

require module //load module before execute

use module1 // macro#module1.__using__

'언어 > elixir' 카테고리의 다른 글

elixir의 특징 및 객체지향과의 비교  (0) 2022.10.18
간단한 elixir 언어 후기  (0) 2022.10.06
Comments