Skip to content

Option.from(value | null | undefined) #11

Description

@Cre3per

Hi!

I'm currently adding Option to a project of mine and am surprised there is no Option.from(value | null | undefined).
A concrete use case would be

const array = [ 1, 2, 3 ];
const found = Option.from(array.find(4));

I'm aware of Option.from(() => array.find(4)), but that seems a little verbose for such simple conversions.


This feature is API-incompatible with the current from(), consider

function thirdParty(): undefined | () => number;

function getFn(): Option<() => number> {
  return Option.from(thirdParty()); // from() can't know if it is supposed to call the function or not
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions