vtm/quelldatein/basis/fehlermonade.ts

100 lines
1.4 KiB
TypeScript
Raw Normal View History

2017-11-08 11:30:34 +01:00
/**
* @author kcf <vidofnir@folksprak.org>
*/
interface schnittstelle_fehlermonade<typ_wert>
{
/**
* @author kcf <vidofnir@folksprak.org>
*/
ist_schlicht() : boolean;
/**
* @author kcf <vidofnir@folksprak.org>
*/
lesen() : typ_wert;
}
/**
* @author kcf <vidofnir@folksprak.org>
*/
class klasse_nichts<typ_wert>
implements schnittstelle_fehlermonade<typ_wert>
{
/**
* @author kcf <vidofnir@folksprak.org>
*/
public constructor()
{
}
/**
* @author kcf <vidofnir@folksprak.org>
*/
public ist_schlicht() : boolean
{
return false;
}
/**
* @author kcf <vidofnir@folksprak.org>
*/
public lesen() : typ_wert
{
let meldung : string = "ist nichts";
throw (new Error(meldung));
}
}
/**
* @author kcf <vidofnir@folksprak.org>
*/
class klasse_schlicht<typ_wert>
implements schnittstelle_fehlermonade<typ_wert>
{
/**
* @author kcf <vidofnir@folksprak.org>
*/
private wert : typ_wert;
/**
* @author kcf <vidofnir@folksprak.org>
*/
public constructor(wert : typ_wert)
{
this.wert = wert;
}
/**
* @author kcf <vidofnir@folksprak.org>
*/
public ist_schlicht() : boolean
{
return true;
}
/**
* @author kcf <vidofnir@folksprak.org>
*/
public lesen() : typ_wert
{
return this.wert;
}
}