Skip to content

Instantly share code, notes, and snippets.

View buzzdecafe's full-sized avatar
💭
quaquaquaqua

buzzdecafe

💭
quaquaquaqua
View GitHub Profile
function next(current = []) {
if (current.length === 0)
return [1]
if (current.length === 1)
return [1, 1]
return [1, ...nextIter(current), 1]
}
@busypeoples
busypeoples / README.md
Last active February 8, 2022 08:41
Making Impossible States Impossible in ReasonML

Making Impossible States Impossible in ReasonML

Introduction

If you have already seen Richard Feldman's talk entitled "Making Impossible States Impossible" or have read "Designing with types: Making illegal states unrepresentable" then you can skip the explanations and just head straight to the Reason examples.

This post is intended to display how to model your Reason Application to prevent creating impossible states. The benefits of being able to design a feature in this way include avoiding having to deal with complex test scenarios regarding defined business rules and a clear documentation of what is possible just by looking at the type definition. Long story short, let's see how this all works by implementing an example.

Requirements

@ChrisPenner
ChrisPenner / TicTacToe.hs
Last active August 26, 2017 18:18
Type-safe game of TicTacToe
{-# language DeriveFunctor #-}
{-# language DataKinds #-}
{-# language GADTs #-}
{-# language ViewPatterns #-}
{-# language TypeFamilies #-}
module Prog where
import Data.Function ((&))
-- | Either X, O, or Nothing
@i-am-tom
i-am-tom / Lazy.js
Last active January 13, 2024 01:35
A Fantasy Land-compliant type for lazy computation.
const fl = require('fantasy-land')
//- Lazy holds a vaue in a thunk, effectively delaying
//- evaluation until required. This is useful when we're
//- in a situation with either very large data set or
//- cyclical data.
//@ make stack-safe.
//> type Lazy a = Unit -> a
function Lazy(run) {
@lexi-lambda
lexi-lambda / Main.hs
Last active July 5, 2023 18:01
Minimal Haskell implementation of Complete and Easy Bidirectional Typechecking for Higher-Rank Polymorphism
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
module Language.HigherRank.Main
( Expr(..)
, EVar(..)
, Type(..)
, TVar(..)
, TEVar(..)
, runInfer
) where
@srdjan
srdjan / 100+ different counter apps...
Last active May 6, 2024 05:13
100+ different js counter apps...
100+ different js counter apps...
@jaysoo
jaysoo / global-ramda-trace.js
Last active February 23, 2019 22:17
Add a trace function for debugging functional JS code
/*
* Top level index.js
*/
let R = require('ramda')
global.trace = msg => R.tap(x => console.log(msg, x))
/*
* ...
*
@DrBoolean
DrBoolean / binary_baby_transformer.js
Last active December 1, 2020 03:12
StateT is useful
import {StateT} from 'fantasy-states'
import Task from 'data.task'
import {prop, compose, map, chain, merge, always} from 'ramda'
// Unfortunately Binary Gendered Baby Page
//==========================================
// data App a b c = App State a (Task b c)
const App = StateT(Task)
const {get, put, modify} = App;
@DrBoolean
DrBoolean / binary_baby.js
Created January 7, 2016 21:04
State Monad is useful example
import State, {get, put, modify} from 'fantasy-states'
import {prop, compose, map, chain, merge, always} from 'ramda'
// Unfortunately Binary Gendered Baby Page
//==========================================
const babies = [{id: 2, name: 'Anjali', sex: 'F'}, {id: 3, name: 'Antonio', sex: 'M'}]
// isFemale :: Baby -> Bool
@DrBoolean
DrBoolean / mcft.js
Created December 30, 2015 04:44
Monoidal Contravariant Functors and Transducers
const daggy = require('daggy');
const {foldMap} = require('pointfree-fantasy')
const {concat, toUpper, prop, identity, range, compose} = require('ramda');
// Contravariant functors usually have this shape F(a -> ConcreteType).
// In other words, some type holding a function which is parametric on its input, but not output.
// They don't always have that shape, but it's a good intuition
// Covariant functors are what we're used to, which are parametric in their output
//================================================================