Merge pull request 'backend: Cleanup prelude directory' (#199) from backend-cleanup-prelude into main

Reviewed-on: FoundKeyGang/FoundKey#199
This commit is contained in:
Norm 2022-10-11 14:47:40 +00:00
commit 20a6140e9a
5 changed files with 1 additions and 57 deletions

View file

@ -84,7 +84,7 @@ export function groupOn<T, S>(f: (x: T) => S, xs: T[]): T[][] {
return groupBy((a, b) => f(a) === f(b), xs); return groupBy((a, b) => f(a) === f(b), xs);
} }
export function groupByX<T>(collections: T[], keySelector: (x: T) => string) { export function groupByX<T>(collections: T[], keySelector: (x: T) => string): Record<string, T[]> {
return collections.reduce((obj: Record<string, T[]>, item: T) => { return collections.reduce((obj: Record<string, T[]>, item: T) => {
const key = keySelector(item); const key = keySelector(item);
if (!Object.prototype.hasOwnProperty.call(obj, key)) { if (!Object.prototype.hasOwnProperty.call(obj, key)) {

View file

@ -1,3 +0,0 @@
export function gcd(a: number, b: number): number {
return b === 0 ? a : gcd(b, a % b);
}

View file

@ -1,20 +0,0 @@
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,
};
}

View file

@ -1,15 +0,0 @@
export function concat(xs: string[]): string {
return xs.join('');
}
export function capitalize(s: string): string {
return toUpperCase(s.charAt(0)) + toLowerCase(s.slice(1));
}
export function toUpperCase(s: string): string {
return s.toUpperCase();
}
export function toLowerCase(s: string): string {
return s.toLowerCase();
}

View file

@ -1,18 +0,0 @@
import * as assert from 'assert';
import { just, nothing } from '../../src/prelude/maybe.js';
describe('just', () => {
it('has a value', () => {
assert.deepStrictEqual(just(3).isJust(), true);
});
it('has the inverse called get', () => {
assert.deepStrictEqual(just(3).get(), 3);
});
});
describe('nothing', () => {
it('has no value', () => {
assert.deepStrictEqual(nothing().isJust(), false);
});
});