我有以下的(人为)代码: dbconn # this var holds the database connection
get_from_cache("missing_key")
defp get_from_cache(key) do
Cachex.get(:my_cache, key, fallback: &from_db/1)
end
defp from_db(key)
我有一个元素列表,我使用Enum.chunk_every方法将它转换为列表列表。 的代码是这样的: matrix = Enum.chunk_every(list_1d, num_cols)
Now I want to loop over the matrix and access the neighbors
只需如果我有列表[1,2,3,4,5,6,1,2,3]它被转换成一个3×3矩阵像:
我有这样 check_file(url) |>test |> foo
TRE功能check_file返回 {:ok,_} or {:error,_}
我有一个模式匹配 def test({:ok,_}) do
IO.puts "ok";
end
def test({:error,_}) do
IO.puts "KO, debug and stop!
在Python我有使用“轮询”对象,其轮询阻断等待消息插座和放开毫秒的指定次数后的选项(在壳体下面,1000,在同时真块): import zmq
# now open up all the sockets
context = zmq.Context()
outsub = context.socket(zmq.SUB)
outsub.bind("tcp://" + myip + ":"
我想让下面的代码块返回值不等于0或n。但有时它返回的值等于0. def get_random(n, num) do
random = returns some number
IO.puts random
if random == n or random == 0 do
get_random(n, num)
end
random
end
我想从列表a中删除列表b中找到的元素。 执行此代码后,列表a正在打印[1,2,3,4]。 defmodule Test do
def listing do
a = [1,2,3,4]
b = [3,4,5,6]
Enum.each b, fn elemB ->
a = Enum.filter(a, fn(x) -> x != elemB == true