Skip to content

Drop Option.FromBoolean in favour of a SelectMany overload for the pair bool, Option<T> #817

@FreeApophis

Description

@FreeApophis

I know, hear me out:

This means instead of

Option.FromBoolean(boolean, something);

you would write

from _ in boolean
select something;

this get especially interesting if you have a combination like this real example:

private static Option<IFormFile> GetFormFile(Request request)
  => request.HasFormContentType
    ? request.Form.Files.FirstOrNone()
    : Option<IFormFile>.None;

With FromBoolean:

private static Option<IFormFile> GetFormFile(Request request)
  => Option.FromBoolean(request.HasFormContentType, request.Form.Files.FirstOrNone()).SelectMany(Identity);

With SelectMany:

private static Option<IFormFile> GetFormFile(Request request)
  => from _ in request.HasFormContentType
     from file in `request.Form.Files.FirstOrNone()`
     select file;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions