Group-like structures | |||||
---|---|---|---|---|---|
Totalityα |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# lib/witchcraft/monoid.ex | |
properties do | |
def left_identity(data) do | |
a = generate(data) | |
# a == TypeClass.Property.Generator.Function.generate(data) | |
# but that input will get ignored. | |
if is_function(a) do | |
equal?(Semigroup.append(Monoid.empty(a), a).("foo"), a.("foo")) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule TypeClass.Property do | |
@moduledoc "A *very* simple prop checker" | |
# (...) | |
@doc "Run all properties for the type class" | |
def run!(datatype, class, prop_name, times \\ 100) do | |
property_module = Module.concat(class, Property) | |
# Irrelevant parts in this scenario are commented out. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule TypeClass do | |
# (...) | |
defmacro definst(class, opts, do: body) do | |
[for: datatype] = opts | |
quote do | |
# The type class protocol's instance implementation goes into | |
# `type_class.Proto.datatype` (in the case of `Monoid`, this will |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import TypeClass | |
################ | |
# DEPENDENCIES # | |
################ | |
extend Witchcraft.Semigroup, alias: true | |
############ | |
# PROTOCOL # | |
############ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Aquir.Users.Read.Schemas.User do | |
use Ecto.Schema | |
alias Aquir.Users.Read.Schemas, as: RS | |
@primary_key {:user_id, :binary_id, autogenerate: false} | |
schema "users" do | |
has_one :credential, RS.UsernamePasswordCredential, | |
foreign_key: :user_id |
NOTE: All links to the Elixir github repo and documentation are fixed to version 1.7.4.
"Elixir allows us to derive a protocol implementation based on the Any
implementation"2 using @derive
. The [Kernel.@/1
][2] macro compiles to a call to [Module.get_attribute/2
][3] function3.
Got bogged down looking at Kernel.@/1
definition: what is does the curly brace do in the definition? (i.e., defmacro @{..}
)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Understanding iOS views*/ | |
/* In ViewController.swift after creating a Single View App. */ | |
import UIKit | |
class ViewController: UIViewController { | |
override func viewDidLoad() { | |
super.viewDidLoad() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Mixing `Agent.cast/2` and `Agent.update/3` | |
# Ignoring the state here, hence `:ok` | |
Agent.start_link(fn -> :ok end, name: :lofa) | |
f = fn (command, t) -> | |
apply(Agent, command, [ | |
:lofa, | |
fn _ -> # becuase state is ignored | |
Process.sleep(t) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule UniqueUsername do | |
use Agent | |
def start_link(_) do | |
Agent.start_link(fn -> MapSet.new() end, name: __MODULE__) | |
end | |
def claim(name) do | |
name_is_taken = Agent.get(__MODULE__, &MapSet.member?(&1, name)) |