Skip to content

Commit

Permalink
Merge pull request #11650 from DamnClin/null-optional
Browse files Browse the repository at this point in the history
Handle null in Optional.ofNullable
  • Loading branch information
murdos authored Dec 28, 2024
2 parents f924fec + ea85cbf commit 0b1f97c
Showing 1 changed file with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export abstract class Optional<Value> {
return new ValuatedOptional(value);
}

static ofNullable<Value>(value: Value | undefined): Optional<Value> {
static ofNullable<Value>(value: Value | undefined | null): Optional<Value> {
if (value === undefined || value === null || checkIsNaN(value)) {
return Optional.empty();
}
Expand All @@ -18,15 +18,25 @@ export abstract class Optional<Value> {
}

abstract map<Output>(mapper: (value: Value) => Output): Optional<Output>;

abstract flatMap<Output>(mapper: (feature: Value) => Optional<Output>): Optional<Output>;

abstract or(factory: () => Optional<Value>): Optional<Value>;

abstract orElse(value: Value): Value;

abstract orElseGet(factory: () => Value): Value;

abstract orElseThrow<U = Error>(throwable?: () => U): Value;

abstract filter(predicate: (value: Value) => boolean): Optional<Value>;

abstract isEmpty(): boolean;

abstract isPresent(): boolean;

abstract ifPresent(consumer: (feature: Value) => void): void;

abstract toArray(): Value[];
}

Expand Down

0 comments on commit 0b1f97c

Please sign in to comment.