This file contains 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
module pipe_forward_test | |
(|>) x y = y x | |
add x y = x + y | |
add_one x = add 1 x | |
res = 2 |> add_one |
This file contains 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 Html exposing (text) | |
(>>=) x y = Result.andThen y x | |
-- We need | |
r = Ok "hello" | |
|> Result.andThen (\x -> Ok " world" | |
|> Result.andThen (\y -> Ok (x ++ y))) | |
r2 = Ok "hello" |
This file contains 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 Html exposing (..) | |
worldData = | |
{ people = | |
[ { money = 129825, name = "Alice Brown" } | |
, { money = 100, name = "John Smith" } | |
, { money = 50000000000, name = "Scrooge McDuck" } | |
, { money = 2870, name = "Charlie Johnson" } | |
, { money = 8273280, name = "Michael Smith" } | |
] |
This file contains 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 DeepMerge do | |
defp _merge(key, v1, v2) when is_map(v1) do | |
Map.merge(v1, v2, &_merge/3) | |
end | |
defp _merge(key, v1, v2), do: v2 | |
def merge(map1, map2) when is_map(map1) and is_map(map2) do | |
Map.merge map1, map2, &_merge/3 | |
end |
This file contains 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
type attribute = | Attribute of string * string | |
type node = | |
| Node of string * (attribute list) * (node list) | |
| Text of string | |
let element name attrs nodes = | |
Node (name, attrs, nodes) | |
let attr k v = |
This file contains 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
(defn- decode-huffman [nodes buffer] | |
(string/join (loop [byte-pos 0 bits (first buffer) | |
node (last nodes) | |
bits-remaining 8 output []] | |
(if (= 0 bits-remaining) | |
(recur (inc byte-pos) (nth buffer (inc byte-pos)) node 8 output) | |
(let [next-node (if (bit-test bits 7) :right :left)] | |
(if (= 255 (:right node)) | |
(if (not= (:value node) "|") |
This file contains 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
(defmacro pln [& args] | |
(let [operator-count (dec (/ (count args) 2)) | |
operators (take operator-count args) | |
values (drop operator-count args) | |
op-vals (map vector operators (next values))] | |
(loop [form (first values) | |
op-vals op-vals] | |
(if (not-empty op-vals) |
This file contains 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
tokiPona = lambda num: (num / 2) * "twu " + ("wan" if num % 2 else "") |
This file contains 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
(defn numberToTokiPona [num] | |
(clojure.string/join " " | |
(loop [n num strs []] | |
(cond | |
(> n 1) (recur (- n 2) (conj strs "twu")) | |
(= n 1) (recur (- n 1) (conj strs "wan")) | |
:else strs)))) |
This file contains 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
let numberToTokiPona num = | |
let rec addNum num str = | |
if num >= 2 then addNum (num-2) (str ^ "twu ") | |
else if num = 1 then addNum (num-1) (str ^ "wan ") | |
else str | |
in | |
if num > 0 then addNum num "" | |
else "ala";; | |
print_string (numberToTokiPona 19);; |