Skip to content

Instantly share code, notes, and snippets.

@gneuvill
Last active October 18, 2017 11:00
Show Gist options
  • Save gneuvill/24845babab885c9a8ff95389fca67ced to your computer and use it in GitHub Desktop.
Save gneuvill/24845babab885c9a8ff95389fca67ced to your computer and use it in GitHub Desktop.
import * as _Maybe from "./maybe"
import {maybe} from "./maybe"
import {Do} from "./syntax"
import Maybe = _Maybe.Maybe
type Person = {
name: string
age: number
}
type Id = string
const getName = (id: Id): Maybe<string> =>
(id === "foo") ? _Maybe.just("Foo") : _Maybe.nothing()
const getAge = (id: Id): Maybe<number> =>
(id === "foo") ? _Maybe.just(34) : _Maybe.nothing()
// doesn't compile : cannot reconcile HKT<"Maybe", { string, number}> with Maybe<Person>
const mbPers: Maybe<Person> = Do._(maybe
, () => getName("foo")
, _ => getAge("foo")
, (name, age) => _Maybe.just({ name: name, age: age}))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment