我有以下的(人爲)代碼: 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