OptTFlatMap Method

Overload List

FlatMapTOut(FuncT, OptTOut) Returns None when IsNone; map(val) when IsSome flattening the result. Shorthand combining Map and Flatten calls.
C#
static Opt<User> GetOptionalUser() {
    // method that tries to get the user, which can be omitted.
    ...
}
static Opt<string> GetNickname(User user) {
    // method that tries to get the nickname of the passed-in user; which is optional
    ...
}
Opt<string> nickname = GetOptionalUser().FlatMap(GetNickname);
// equivalent to both below:
nickname = GetOptionalUser().FlatMap(user => GetNickname(user));
nickname = GetOptionalUser().Map(user => GetNickname(user) /*Opt<Opt<string>>*/).Flatten();
FlatMapTOut(FuncT, TaskOptTOut) (async version) Returns None when IsNone; map(val) when IsSome flattening the result. Shorthand combining Map and Flatten calls.
C#
static Opt<User> GetOptionalUser() {
    // method that tries to get the user, which can be omitted.
    ...
}
static Opt<string> GetNickname(User user) {
    // method that tries to get the nickname of the passed-in user; which is optional
    ...
}
Opt<string> nickname = GetOptionalUser().FlatMap(GetNickname);
// equivalent to both below:
nickname = GetOptionalUser().FlatMap(user => GetNickname(user));
nickname = GetOptionalUser().Map(user => GetNickname(user) /*Opt<Opt<string>>*/).Flatten();

See Also