Skip to content

Instantly share code, notes, and snippets.

View richdouglasevans's full-sized avatar
✌️

Rich richdouglasevans

✌️
  • Oxford, England
View GitHub Profile
open System
/// A train carriage can have a number of different features...
type Feature = Quiet | Wifi | Toilet
/// Multiple classes
type CarriageClass = First | Second
/// Carriages can be either for passengers or the buffet cart
type CarriageKind =
@enricopolanski
enricopolanski / eq1.md
Last active May 25, 2020 12:36
Equivalence #1

Suppose we want a set of unique { x, y } points to plot on a graph.

this expression:

new Set([
  { x: 1, y: 1 },
  { x: 1, y: 1 },
]);
@ruizb
ruizb / advanced-example.md
Last active September 26, 2023 20:21
Reader monad example using fp-ts

The following section is not part of monet.js documentation, but I think it's worth showing how we can compose readers using fp-ts.

Reader composition

Let's say we have the following piece of code:

interface Dependencies {
  logger: { log: (message: string) => void }
 env: 'development' | 'production'
/** Used by Flavor to mark a type in a readable way. */
export interface Flavoring<FlavorT> {
_type?: FlavorT;
}
/** Create a "flavored" version of a type. TypeScript will disallow mixing flavors, but will allow unflavored values of that type to be passed in where a flavored version is expected. This is a less restrictive form of branding. */
export type Flavor<T, FlavorT> = T & Flavoring<FlavorT>;
/** Used by Brand to mark a type in a readable way. */
export interface Branding<BrandT> {
_type: BrandT;
@gcanti
gcanti / io-ts2form.ts
Created August 25, 2018 13:37
Automatically building a form from a `io-ts` type
import * as t from 'io-ts'
import * as React from 'react'
import { render } from 'react-dom'
type Field = t.StringType | t.NumberType | t.BooleanType
interface Form extends t.InterfaceType<{ [key: string]: Field }> {}
const toReactElement = (f: Form | Field): React.ReactElement<any> => {
// f is a tagged union
switch (f._tag) {
@busypeoples
busypeoples / UIPattern.re
Last active January 28, 2019 15:31
Slaying a UI Anti Pattern in ReasonML
/*
Slaying a UI Anti Pattern in ReasonML
Based on Kris Jenkins original writing.
http://blog.jenkster.com/2016/06/how-elm-slays-a-ui-antipattern.html
*/
type remoteData 'e 'a =
| NotAsked
| Loading
| Failure 'e
| Success 'a;
@i-am-tom
i-am-tom / fanfic.md
Last active April 14, 2018 22:13
The morning of Gary Burgess, 01/09/17

"For services to the PureScript Community, Gary Burgess!"

You've done it, Gary. Moore, Lineker, Coleman, and now Burgess. All the work was worth it. The halls erupted with praise. Children dressed as Space Ghost, teens with "I only get high on Halogen" t-shirts, a giant banner held aloft with the message, "Tuple @garyb me". Through the noise of the crowds and Phil's uninterpretable Northern accent, he barely managed to hear his theme tu-

BZZP. BZZP.

@spikeheap
spikeheap / sessions.md
Last active August 20, 2017 15:09
Introduction to Coaching Workshop, Oxford 2017-08-12

Workshop sessions

First we split into groups of 5 and asked:

What experience do you have of coaching or mentoring? What’s the difference between mentoring and coaching?

Session 1

Once we’d committed to confidentiality and making the workshop a safe space, in pairs we covered:

What is it like doing your job?

@bahmutov
bahmutov / index.js
Created August 10, 2017 15:37
Kleisli composition example (JSON parsing + deep property)
// following along https://medium.com/@luijar/kliesli-compositions-in-javascript-7e1a7218f0c4
const R = require('ramda')
const Maybe = require('ramda-fantasy').Maybe
// parse JSON string into object
// parse :: String -> Object | Null
function parse(s) {
try {
return JSON.parse(s)
} catch (e) {
@i-am-tom
i-am-tom / bifunctor-profunctor.js
Created June 26, 2017 18:32
The main examples from the "Bifunctor + Profunctor" post.
const { Left, Right } = require('fantasy-eithers')
const daggy = require('daggy')
Function.prototype.map = function (f) {
return x => f(this(x))
}
//- Where everything changes...
const login = user =>
user.name == 'Tom'