Skip to content

Commit

Permalink
perf: create single shared none instance
Browse files Browse the repository at this point in the history
Because all nones are equivalent, we can share a single instance. This
should save a decent amount of memory and cpu cycles from not building
the `None` class constantly.
  • Loading branch information
andy.patterson authored and andnp committed Jun 7, 2018
1 parent cdcb8b9 commit a3a064b
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/none.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,5 @@ export default class None<T> extends Maybe<T> {
asNullable(): T | null { return null; }
}

export const none: <T>() => Maybe<T> = None.none;
const _noneSingleton = None.none<any>();
export const none = <T>(): Maybe<T> => _noneSingleton;

0 comments on commit a3a064b

Please sign in to comment.