This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict' | |
/*@flow*/ | |
// Creates a function that clones dates and shifts by the | |
// seconds specified. | |
// Example: | |
// >>> import { seconds } from './shift' | |
// >>> const fiveSecondsLater = seconds(5) | |
// >>> const d = new Date() | |
// >>> fiveSecondsLater(d) - d |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Parse where | |
import Prelude | |
import Data.Traversable (scanr) | |
import Data.List (List(Cons), (:)) | |
data Loc = Loc { line :: Int } | |
data LocRange | |
= LocRange { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
/*@flow*/ | |
/* | |
Here's an example of how to enforce at compile-time that an object is | |
validated before it is used in code where it could potentially fail at | |
run-time. | |
This one works by "containing" an object purely in another flow type. | |
(Sorta like a `newtype` in Haskell.) Actually, this code cheats; the |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
/*@flow*/ | |
// TODO: parameterize by argument type when flow supports it: | |
// type Func<A,R> = (...args:A) => R | |
// type Adviser<F:Func<A,R>> = (x:F) => F | |
// export type TraceAdvice<A,R> = (args:A, result:R) => mixed | |
type Func<R> = () => R | |
type Adviser<F:Function> = (x:F) => F |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Sequence an array of promise-producing functions. | |
export const sequence | |
: (ops:Array<() => Promise>) => Promise | |
= ops => | |
ops.reduce((p, op) => p.then(op), Promise.resolve()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
/*@flow*/ | |
class Square { | |
/*:: | |
x: number; | |
y: number; | |
w: number; | |
*/ | |
constructor (x/*: number*/, y/*: number*/, w/*: number*/) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
/* @flow */ | |
// A typesafe shopping cart in flowtype. | |
// Flow relies heavily on EcmaScript constructs, primarily `class` to | |
// define types. This feels quite restrictive if you've been using a strongly | |
// typed language, such as Haskell. Still, I managed to build this "safe" | |
// suite of shopping cart functions that prevents the developer from doing | |
// nonsensical things with the cart. For instance, you can't compile code |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
/* @flow */ | |
// Cart items. | |
type SKU = string; | |
type Item = { | |
sku: SKU, | |
quantity: number |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module PhantomVisit ( | |
Visit, | |
CallAhead, | |
Remote, | |
WalkIn, | |
Rsv, | |
callAhead, | |
remote, | |
walkIn, | |
rsv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class Maybe { | |
constructor (f) { | |
this._run = f; | |
} | |
/** | |
* Transform the result of a maybe operation. | |
*/ | |
map (f) { |