Skip to content

Instantly share code, notes, and snippets.

@tatchi
tatchi / counties.json
Created August 23, 2022 08:11 — forked from rusty-key/counties.json
Countries
[
{"label": "Afghanistan", "value": "af",
{"label": "Åland Islands", "value": "ax"},
{"label": "Albania", "value": "al"},
{"label": "Algeria", "value": "dz"},
{"label": "American Samoa", "value": "as"},
{"label": "AndorrA", "value": "ad"},
{"label": "Angola", "value": "ao"},
{"label": "Anguilla", "value": "ai"},
{"label": "Antarctica", "value": "aq"},
@tatchi
tatchi / form.ml
Created March 15, 2022 17:56 — forked from andreypopp/form.ml
type _ t =
| Form_value : 'a -> 'a t
| Form_field : string -> string t
| Form_map : 'a t * ('a -> ('b, string) result) -> 'b t
| Form_both : 'a t * 'b t -> ('a * 'b) t
let value v = Form_value v
let empty = Form_value ()
let field name = Form_field name
let map v f = Form_map (v, f)
type 'a t
(** [a t] represents a form parser which produces a value of type [a]. *)
val field : string -> string t
(** [field name] parses a string typed value for form field [name]. *)
val map : 'a t -> ('a -> ('b, string) result) -> 'b t
(** [map v f] validates [v] with [f]. *)
val both : 'a t -> 'b t -> ('a * 'b) t
@tatchi
tatchi / machine.js
Created April 8, 2020 13:03
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
type Views = 'All' | 'Details';
interface defaultValue<T> {
_: () => T;
}
export function foldL<R>(
fa: Views,
obj:
| { [K in Views]: (a: Views) => R }
export const createSumType = types => {
const values = Object.values(types);
return Object.entries(types).reduce(
(acc, [k, v]) => ({
...acc,
[k]: {
value: v,
matchWith: o => {
const keys = Object.keys(o);
if (!keys.includes("_")) {
import React, { useReducer } from 'react';
import './styles.scss';
type Views = 'All' | 'Details';
type State = { view: Views };
export type AppActions =
| {
readonly type: 'ResetView';