When using simultaneous assignment, all the expressions on the RHS are evaluated before any assigment is done on the LHS.
Simultaneous assignment can greatly simplify the presentation of code.
def fibonacci():
a = 0
b = 1
Generators are implemented with syntax very similar to functions, but instead of returning values, a yield statement is executed to indicate each element in the series
Consider the goal of computing all factors of a positive integer. A traditional function might return a list contating all factors, implemeted as follows:
def factors(n): # traditional function that computes factors
results = [] # store factors in a new list
for k in range(1, n+1):
if n % k == 0: # divides evenly, thus k is a factor
results.append(k) # add k to the list of factors
{ | |
"data": {"values": | |
[ | |
{"_submitted_by": "dalli", | |
"INTRO_DISTRICT": [ | |
"Afgooye" | |
], | |
"count": 1 | |
}, | |
{"_submitted_by": "dalli", |
-- v5 | |
----------------------------------------------------------- basic instance info | |
-- show db version | |
SELECT version(); | |
-- uptime | |
SELECT pg_postmaster_start_time(); | |
-- show connections |
git config diff.sopsdiffer.textconv "sops --decrypt --config /dev/null" |
mix phx.new --binary-id budgie
# add docker-compose.yml below
mix setup
mix phx.gen.auth Accounts User users --hashing-lib argon2
Edit mix.ex
defp deps do
defmodule AppNameWeb.LvLiveTest do | |
use UrlshortenerWeb.ConnCase, async: true | |
import Phoenix.LiveViewTest | |
describe "LV test" do | |
test "we can render the view", %{conn: conn} do | |
{:ok, _lv, html} = live(conn, ~p"/") | |
# open_browser(lv) |
~r/^[A-Za-z0-9]+$/ | |
~r/^[A-Za-z0-9]{6}$/ |