Since Elixir 1.2, Elixir has had the with macro to assist with more expressive control flow. Instead of deeply nested case and if/else blocks, you can have one single with block to express the same logic but in a more elegant and readable way. I’ll explore how you can utilize with to improve your code. with Basics with works by taking a list of clauses to be matched in order. If all clauses match,
The labels that are jumped to from the select_val match then are checking that the rest of the string matches. The select_val is being generated in label(28)’s block because there is a group of clauses for render_template generated in Phoenix.Template.__before_compile__ My theory is that this is how BEAM makes pattern matching efficient in general: it finds prefixes that can be matched against wit
For many API applications, there comes a time when the application needs to save images uploaded to the server either locally or on a CDN. Luckily for us, Elixir and Phoenix provide the tools we need to build a simple image upload API. The Simple API Let’s define exactly how this API is supposed to work: accept a request containing a base64 encoded image as a field preserve the image extension by
alias __MODULE__ This one looks mysterious at first, but once we break it down, it’s very straightforward. alias allows you to define aliases for the module name, for example: alias Foo.Bar will set up an alias for module Foo.Bar, and you can reference that module with just Bar. __MODULE__ is a compilation environment macros which is the current module name as an atom. Now you know alias __MODULE_
When writing Elixir apps you’ll typically find yourself building up state in a map. Typically these maps contain deep nesting. Updating anything deeply nested means you have to write something like: my_map = %{ foo: %{ bar: %{ baz: "my value" } } } new_bar_map = my_map |> Map.get(:foo) |> Map.get(:bar) |> Map.put(:baz, "new value") new_foo_map = my_map |> Map.get(:foo) |> Map.put(:bar, new_bar_map
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く