/* * Verrückte Turing-Maschinen — A turing complete game * Copyright (C) 2016-2018 kcf * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ module lib_errormonade { /** * @author kcf */ export type type_errormonade = lib_call.type_complex; /** * @author kcf */ export function create_nothing ( ) : type_errormonade { return ( lib_call.wrap ( "nothing", { } ) ); } /** * @author kcf */ export function create_just ( value : type_value ) : type_errormonade { return ( lib_call.wrap ( "just", { "value": value } ) ); } /** * @author kcf */ export function filled ( errormonade : type_errormonade ) : boolean { return ( lib_call.distinguish ( errormonade, { "nothing": ({}) => false, "just": ({"value": value}) => true, } ) ); } /** * @author kcf */ export function read ( errormonade : type_errormonade ) : type_value { return ( lib_call.distinguish ( errormonade, { "nothing": ({}) => {throw (new Error("read von nothing"));}, "just": ({"value": value}) => value, } ) ); } /** * @author kcf */ export function propagate ( errormonade : type_errormonade, funktion : (value1 : type_value1)=>type_errormonade ) : type_errormonade { return ( lib_call.distinguish ( errormonade, { "nothing": ({}) => create_nothing(), "just": ({"value": value1}) => funktion(value1), } ) ); } }