summaryrefslogtreecommitdiff
path: root/src/prelude/maybe.ts
blob: 0b4b543ca5f2e6179d19cb8e982349346f03dc52 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
export interface IMaybe<T> {
	isJust(): this is IJust<T>;
}

export interface IJust<T> extends IMaybe<T> {
	get(): T;
}

export function just<T>(value: T): IJust<T> {
	return {
		isJust: () => true,
		get: () => value
	};
}

export function nothing<T>(): IMaybe<T> {
	return {
		isJust: () => false,
	};
}