public variant Result { Ok(T), Error(E), Other(T, E); /*public then(fn as function(result as T) as Result) as Result { return match this { Ok(result) => fn(result), Error(error) => Error(error), Other(result, error) => fn(result) }; }*/ //public handle(handler as function(error as E) as Result) as Result { // return match this { // Ok(result) => Ok(result), // Error(error) => handler(error) // }; //} public expect() as T { return match this { Ok(result) => result, Error(error) => panic "expect() called on an error value", Other(result, error) => result }; } public orElse(other as T) as T { return match this { Ok(result) => result, Error(error) => other, Other(result, error) => result }; } public orElse(other as function(error as E) as T) as T { return match this { Ok(result) => result, Error(error) => other(error), Other(result, error) => result }; } } function makeResult() as Result => Ok("10"); function makeErrResult() as Result => Error("10"); println(makeResult().orElse("Ten")); println(makeResult().expect()); println(makeErrResult().orElse("Ten")); //CompileException [TYPE_ARGUMENTS_NOT_INFERRABLE] Could not infer generic type parameters [ParsedExpressionFunction.compile, line 75] //println(makeResult().then(tValue => Result.Ok(tValue)).expect()); //IllegalArgumentException: Cannot retrieve members of undetermined type [TypeMembers., line 71] //println(makeResult().then(a => Ok(a)).expect()); //println(makeResult().then(a as string => Ok(a)).expect()); //CompileException [UNEXPECTED_TOKEN] ) expected [LLparserTokenStream.required, line 97] //Wants to compile a call to function() instead of creating a lambda //println(makeResult().then((function (t as string) as Result)(t => Ok(t))).expect());