elixir

Elixir: error when piping to a function the result of inline comprehension

淺唱寂寞╮ 提交于 2019-12-25 07:24:10
问题 I've noticed something surprising with Elixir's for comprehensions when used to pipe the results into a function. For example, these forms work: foo = fn(list) -> for n <- list do n + 1 end |> Enum.reverse end foo.([1,2,3]) # [4, 3, 2] foo = fn(list) -> for(n <- list, do: (n + 1)) |> Enum.reverse end foo.([1,2,3]) # [4, 3, 2] But this doesn't, as it considers the |> Mod.func on the second line part of the do block of the macro: foo = fn(list) -> for n <- list, do: n + 1 |> Enum.reverse end

Elixir/Phoenix map for the channels payload

匆匆过客 提交于 2019-12-25 07:18:18
问题 Well, I am looking for a good way to pass multiple elements (same column name) that I've retrieved from db into the channels payload. For example: ppl = Repo.all(People) will return two results with id: 1, name: Mike , id: 2, name: John . The name: (column name) is used for both Mike and John, but when passing through channels payload, I can only pass one map, where can't have both name: John, name: Mike at the same time. As I understood channels, we use a map(payload) that is send back to

Shell represents binary

眉间皱痕 提交于 2019-12-25 05:24:54
问题 I have following statement iex(5)> a = <<3>> <<3>> iex(6)> b = <<a::binary>> <<3>> First line, I created a binary with value 3. On third line I want that the shell shows me 00000011 not 3. I know it does not make sense first the create a binary(1.line) then convert to binary again. But I was expecting that shell shows me 00000011 instead of 3. When binary as float like iex(7)> a = << 5.3 :: float >> <<64, 21, 51, 51, 51, 51, 51, 51>> I do not understand, why it shows me this numbers? 回答1:

Elixir's `mix format` configuration options

自古美人都是妖i 提交于 2019-12-25 04:01:33
问题 I'm trying to find a list a configurable options for mix format to put in the formatter config file, but I can't for the life of me find it. It's not in the mix format docs or anywhere else I've looked. Anyone know where I can find this information? 回答1: It turns out that mix format does not have a lot of options to set, and what you see on the mix docs page is exactly what you get. It seems there are not a breadth of settings to make it more opinionated. 回答2: You should read the docs:

Elixir - What is syntax for function definitions?

偶尔善良 提交于 2019-12-25 03:37:28
问题 Using Elixir V1.1.1 on OS X I am having problems getting my head around the Elixir function definition syntax. Given a function definition: def foobar(arg1, arg2), do: <<something>> end It seems that in some cases the comma after the parenthesis is required, other times it is not. Likewise the colon after the 'do' and likewise the closing 'end'. I am sure I am vastly over-complicating the situation, but this seems like a weird setup for a programming language. Under what circumstances are

Failed to connect to Database - Setting up GCP app engine

北城余情 提交于 2019-12-25 02:57:12
问题 I'm trying to setup an instance on my phoenix app. I'm actually able to generate the app but I'm getting an error when trying to connect to the DB: ERROR: 21:11:31.017 [error] Postgrex.Protocol (#PID<0.2223.0>) failed to connect: ** (DBConnection.ConnectionError) tcp connect (/tmp/cloudsql/statcasters:us-central1:statcastersdb): no such file or directory - :enoent I'm not sure what is wrong? The file seems to exist but it seems to say it doesn't: prod.secret.exs: config :statcasters,

Why is Elixir's Enum.count not returning a number? [duplicate]

杀马特。学长 韩版系。学妹 提交于 2019-12-24 23:19:49
问题 This question already has answers here : Elixir lists interpreted as char lists (2 answers) Closed last year . I have the following input: [ [ {"title", "Aaaaaaaaa aaaaaaaaaaa aa aaa oaaaaaaaa"}, {"title", "Aaaaaaa aa aaaa aaa.aa"}, {"title", "Aaaaaaaaaaaa Aaaaaaa, aaa Aaaaaaa"}, {"title", "Aaaa Aaaaaaaa aaaa Aaaaa"}, {"title", "Aaaaaaa Aaaaaaa aaaa Aaaaa"}, {"title", "Aaaaa Aaaaaaa aa Aaaaaa"}, {"title", "Aaaaaaaaa Aaaaa Aaaa Aaaaaaa, Aaa Aaaaaaa"}, {"title", "Aaaaaaaaa Aaaaaaa Aaaaaa

Why is Elixir's Enum.count not returning a number? [duplicate]

故事扮演 提交于 2019-12-24 22:42:04
问题 This question already has answers here : Elixir lists interpreted as char lists (2 answers) Closed last year . I have the following input: [ [ {"title", "Aaaaaaaaa aaaaaaaaaaa aa aaa oaaaaaaaa"}, {"title", "Aaaaaaa aa aaaa aaa.aa"}, {"title", "Aaaaaaaaaaaa Aaaaaaa, aaa Aaaaaaa"}, {"title", "Aaaa Aaaaaaaa aaaa Aaaaa"}, {"title", "Aaaaaaa Aaaaaaa aaaa Aaaaa"}, {"title", "Aaaaa Aaaaaaa aa Aaaaaa"}, {"title", "Aaaaaaaaa Aaaaa Aaaa Aaaaaaa, Aaa Aaaaaaa"}, {"title", "Aaaaaaaaa Aaaaaaa Aaaaaa

Presence not picking up user leave events?

匆匆过客 提交于 2019-12-24 18:50:30
问题 I need to perform some actions when the user leaves a channel (in most cases where they close the tab voluntarily, but there may also be a connection loss/timeout etc.) According to posts like https://elixirforum.com/t/phoenix-presence-run-some-code-when-user-leaves-the-channel/17739 and How to detect if a user left a Phoenix channel due to a network disconnect?, intercepting the "presence_diff" event from Presence seems to be a foolproof way to go, as it should also covers the cases where

Creating anonymous functions via macros

孤街醉人 提交于 2019-12-24 17:08:36
问题 I'm tying to make an API where an anonymous function are composed from macros, e.g. transform [x, y], do: x + y transform x, do: x should use the transform head and body[:do] as the heads and bodies for an anonymous function. For example, the above macro calls The example above should be collected into: fn [x, y] -> x + y; x -> x end With unquote fragments it's easy to create new named function def s, but not new anonymous functions: iex> val = 1 iex> fn() -> unquote(val) end ** (CompileError