-
-
Save rightfold/788ab1a3d027988b3c00 to your computer and use it in GitHub Desktop.
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
% cat test/data/union.vl | |
load console | |
union ParseResult with | |
Ok(value: number) | |
Error(reason: string) | |
end | |
do | |
console.log(Ok(42).value) | |
console.log(Error("fail").reason) | |
end | |
% ./build vlinder && esgenerate -c <(echo '{ "comment": true }') <(./vlinder.native test/data/union.vl) | |
Finished, 39 targets (39 cached) in 00:00:01. | |
/* @flow */ | |
'use strict'; | |
var __vlinder = require('vlinder/rt'); | |
var __global = __vlinder.global; | |
var console = __global.console; | |
module.exports.ParseResult = class { | |
}; | |
class Ok$class extends module.exports.ParseResult { | |
constructor(value /* : number */) { | |
super(); | |
this.value = value; | |
} | |
} | |
module.exports.Ok = function (value /* : number */) | |
/* : module.exports.ParseResult */ | |
{ | |
return new Ok$class(value); | |
}; | |
class Error$class extends module.exports.ParseResult { | |
constructor(reason /* : string */) { | |
super(); | |
this.reason = reason; | |
} | |
} | |
module.exports.Error = function (reason /* : string */) | |
/* : module.exports.ParseResult */ | |
{ | |
return new Error$class(reason); | |
}; | |
(function () { | |
console.log(module.exports.Ok(42).value); | |
console.log(module.exports.Error('fail').reason); | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment