Skip to content

Instantly share code, notes, and snippets.

module Form = {
@react.component
let make = () => {
let {clearErrors, control, formState: {errors}, handleSubmit} = Hooks.Form.use(
~option=Hooks.Form.option(
~mode=#onBlur,
~shouldFocusError=false,
~defaultValues=Js.Dict.fromArray([(Values.title, Value.make(""))]),
(),
),
@gaku-sei
gaku-sei / Solid.re
Created October 31, 2020 08:48
Solide + ReasonML
module Node = {
type t;
};
module HyperScript = {
type t;
[@module "solid-js/h"]
external make: (string, 'props, array(t)) => t = "default";
@gaku-sei
gaku-sei / Recoil.re
Last active July 7, 2020 08:49
Attempt to map Recoiljs (https://recoiljs.org/) to ReasonML
type r = [ | `read];
type w = [ | `write];
type rw = [ r | w];
type t('a, 'rights) constraint 'rights = [< rw];
type getArg = {get: 'a 'rights. t('a, [> r] as 'rights) => 'a};
@gaku-sei
gaku-sei / Percentage.re
Created March 2, 2020 02:16
Playing with functors to create an elaborate Percentage module
/* Comes from BsAbstract and Relude */
module type EQ = {type t; let eq: (t, t) => bool;};
type ordering = [ | `less_than | `equal_to | `greater_than];
module type ORD = {include EQ; let compare: (t, t) => ordering;};
module type BOUNDED = {include ORD; let top: t; let bottom: t;};
module type SHOW = {type t; let show: t => string;};
@gaku-sei
gaku-sei / pair_programming_exercises.md
Last active July 2, 2020 03:20 — forked from adambray/pair_programming_exercises.md
Pair Programming Exercises

Number to Ordinal

Finish the function numberToOrdinal, which should take a number and return it as a string with the correct ordinal indicator suffix (in English). That is:

  • numberToOrdinal(1) ==> '1st'
  • numberToOrdinal(2) ==> '2nd'
  • numberToOrdinal(3) ==> '3rd'
  • numberToOrdinal(4) ==> '4th'

Fluid Calculator

@gaku-sei
gaku-sei / UrqlWithInit.re
Created February 7, 2020 06:30
Urql with Init value hook
type t('a) = {
error: option(UrqlCombinedError.t),
loading: bool,
response: AsyncResult.t('a, UrqlCombinedError.t),
};
// request here will be the first value returned by the current hooks
let use = (~request) => {
let (pristine, setPristine) = React.useState(() => true);
@gaku-sei
gaku-sei / UrqlDynamicMutationHook.re
Last active February 6, 2020 10:33
Urql useDynamicMutation with Init value
type t('a) = {
error: option(UrqlCombinedError.t),
loading: bool,
response: AsyncResult.t('a, UrqlCombinedError.t),
};
let use = (~definition) => {
let (pristine, setPristine) = React.useState(() => true);
let (hasLoaded, setHasLoaded) = React.useState(() => false);
@gaku-sei
gaku-sei / Example1.re
Last active February 10, 2020 13:06
Uses Immutable Array with bs-abstract to compile on BuckleScript 7.1.0
// Interfaces
module type FUNCTOR = {
type t('a);
let map: ('a => 'b, t('a)) => t('b);
};
module type ALT = {
include FUNCTOR;
@gaku-sei
gaku-sei / Index.re
Created December 2, 2019 07:42
Play with Indexed Monad in ReasonML (implements https://qiita.com/kimagure/items/a0ee7313e8c7690bf3f5)
open! IndexedBurger;
let burgerSpec: ixBurger(ready, topBunOn, burgerSpec) =
Infix.(
getEmptyPlate
>>=: placeEmptyBun
>>=: addKetchup
>>=: addPatty
>>=: addCheese
>>=: addTopBun
@gaku-sei
gaku-sei / Index.re
Created December 2, 2019 06:00
Play with "void-like" types to re-produce Elm's Task
// Rough implementation of https://package.elm-lang.org/packages/elm/core/latest/Platform-Cmd#Cmd
module Cmd = {
[@bs.deriving accessors]
type t('msg) =
| Cmd('msg);
let make: 'msg => t('msg) = cmd;
};
// Simple https://package.elm-lang.org/packages/elm/core/latest/Task