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

export type Just<T> = Maybe<T> & {
	get(): T
};

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

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