Format: module -> import -> dependency
{
"purescript-arrays": {
"Prelude": "purescript-prelude",
"Control.Alt": "purescript-control",
"Control.Alternative": "purescript-control",
// @flow | |
/* | |
"Proof in functions" by @mbrandonw | |
implemented in JavaScript and using Flow as a static type checker | |
Original post: | |
http://www.fewbutripe.com/swift/math/2015/01/06/proof-in-functions.html |
function updateObj<T: Object>(obj: T, fields: $Shape<T>) : T {
return Object.assign({}, obj, fields)
}
const person1 = { name: 'Giulio', age: 42 }
// I guess here Flow infers that person1 is of type { name: string, age: number }
const person2 = updateObj(person1, { age: 43 } ) // ok
const person2 = updateObj(person1, { a: 1 } ) // error: property `a` of object literal. Property not found
// @flow | |
import { HKT } from '../HKT' | |
import type { Functor } from '../Functor' | |
class IsList {} | |
class Cons<A> { | |
head: A; | |
tail: ListV<A>; |
export default class Eff<EA: Object, A> { | |
run: () => A; | |
constructor(run: () => A) { | |
this.run = run | |
} | |
map<B>(f: (_: A) => B): Eff<EA, B> { | |
return new Eff(() => f(this.run())) | |
} | |
chain<EB: Object, B>(f: (_: A) => Eff<EB, B>): Eff<EA & EB, B> { | |
return Eff.join(this.map(f)) |
Written by @alpacaaa and @GiulioCanti
"Type driven development" is a technique used to split a problem into a set of smaller problems, letting the type checker suggest the concrete implementation, or at least helping us getting there. Here's a practical example
Say for instance that we like to reimplement the function Promise.all
, we'll name it sequence
. Let's start with its signature
// @flow
// Params -> Querystring -> A
type Handler<A, P = void, Q = void> = (p: P, q: Q) => A;
type Id = { id: string };
// config type
type Router<a> = {</a>
// @flow | |
// | |
// library agnostic types and helpers | |
// | |
// keep private | |
class Unit<A> {} | |
class IsMedia {} |
import * as React from 'react' | |
type Witness<A, B, C> = (x: A & B) => C | |
// P = original props | |
// D = defaulted props | |
// U = untouched props | |
function removeProps<P, D extends keyof P, U extends keyof P>(defaults: Pick<P, D>, witness: Witness<Pick<P, D>, Pick<P, U>, P>): (Component: React.ComponentClass<P>) => React.ComponentClass<Pick<P, U>> { | |
return Component => class extends React.Component<Pick<P, U>, void> { | |
render() { |
type Sobriety = 'Sober' | 'Tipsy' | 'Drunk' | 'Paralytic' | 'Unconscious' | |
type Gender = 'Male' | 'Female' | |
interface Person { | |
gender: Gender | |
age: number | |
clothes: Array<string> | |
sobriety: Sobriety | |
} |