Skip to content

Instantly share code, notes, and snippets.

View abiodun0's full-sized avatar

Abiodun abiodun0

View GitHub Profile
@abiodun0
abiodun0 / peano.purs
Last active August 16, 2020 08:32
Simple concept of peano numbers recursive purescuript https://try.purescript.org/?session=6b420eec-23b7-d33f-68fd-94ccca70bf48
module Main where
import Prelude
import Control.Monad.Eff.Console (logShow)
import TryPureScript (render, withConsole)
-- Declare the recursive type.
data Peano = Z | S Peano
-- This allows us to print the type.
@abiodun0
abiodun0 / ramdaReduxReact.js
Created October 15, 2017 08:26
complete Redux with Ramda
const counterReducer = (state = 0, {type}) => {
switch(type) {
case 'INC': return state + 1
case 'DEC': return state - 1
default: return state
}
}
const todoReducer = (state = 0, {type, text}) => {
switch(type) {
@abiodun0
abiodun0 / reselectRamda.js
Last active November 10, 2017 17:19
Reselect Done with Ramda function
const createSelector = (...fns) => R.memoize(R.converge(R.last(fns), R.init(fns)))
// test case
const selector = createSelector(
state => state.a,
state => state.b,
(a, b) => console.log('Called!') || ({
c: a * 2,
d: b * 3
@abiodun0
abiodun0 / higherOrderAbstractSyntax.hs
Created October 10, 2017 01:20
Higher-order abstract syntax for any cartesian-closed category
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
module CCCs where
@abiodun0
abiodun0 / flip.ts
Created October 4, 2017 10:02
Problems with ts
// Typescript can handle monomoprhic functions
const flip = <A, B, C>(f: (a: A) => (b: B) => C): ((b: B) => (a: A) => C) => b => a => f(a)(b)
const foo = (a: string) => (b: number) => a.length - b
// fooFlipped: (b: number) => (a: string) => number
const fooFlipped = flip(foo)
// But can't handle polymorphic functions
const concat = <A>(xs: Array<A>) => (a: A): Array<A> => xs.concat([a])
@abiodun0
abiodun0 / tic-tac-toc.ts
Created September 1, 2017 16:27
Type safety with ts
/*
Type Tac Toe: Advanced Type Safety
==================================
Adapted from http://chrispenner.ca/posts/type-tac-toe
*/
/** Either X, O, or Nothing */
type Piece = 'X' | 'O' | 'N'
/** coordinates */
@abiodun0
abiodun0 / ui-states.re
Created August 18, 2017 16:44
Display UI states nicely in reason
/* Slaying a UI Anti Pattern in Reason */
type remoteData 'e 'a =
| Nothing
| Loading
| Failure 'e
| Success 'a;
type item = {
userId: int,
@abiodun0
abiodun0 / daggy.ts
Last active August 6, 2017 06:39
Daggy typescript implementation
//
// product types
//
/*
// A coordinate in 3D space
export type Coord = {
readonly x: number
readonly y: number
readonly z: number
@abiodun0
abiodun0 / ramdareact.js
Created August 2, 2017 21:50
When react act as the v.. composable view with Ramda
import React from "react";
import { render } from "react-dom";
import R from "ramda";
const users = [
{ id: 1, name: "foo", points: 45 },
{ id: 2, name: "bar", points: 22 },
{ id: 3, name: "baz", points: 79 },
{ id: 4, name: "bla", points: 54 }
];