hkt-toolbelt
Version:
Functional and composable type utilities
51 lines (50 loc) • 1.46 kB
TypeScript
import { $, Conditional, Function, Kind, List, Matrix, Type } from '..';
type NeverIf = $<Kind.Pipe, [
Conditional.If,
$<Kind.ApplyN, [$<Function.Constant, never>, Function.Identity]>
]>;
type NeverIfEqualToAnyOf = $<Kind.Pipe, [List.IncludesValue, NeverIf]>;
type DuplicatesExcludingZero = $<Kind.Pipe, [
List.Duplicates,
$<List.Remove, 0>
]>;
type NeverIfDuplicate = $<Kind.Pipe, [
$<Kind.Juxt, [
$<Kind.Pipe, [DuplicatesExcludingZero, NeverIfEqualToAnyOf]>,
Function.Identity
]>,
$<Kind.Uncurry, List.Map>
]>;
type ValidateRows = $<List.Map, NeverIfDuplicate>;
type ValidateColumns = $<Kind.PipeWeak, [
Matrix.Columns,
ValidateRows,
Matrix.Columns
]>;
type BuildFromBoxes = $<Kind.Pipe, [
$<List.Map, $<List.Chunk, 3>>,
$<List.Chunk, 3>,
Matrix.Columns,
Matrix.Combine
]>;
type GetBoxes = $<Kind.Pipe, [
$<$<Matrix.Chunk, 3>, 3>,
$<List.Map, $<List.FlattenN, 1>>
]>;
type ValidateBoxes = $<Kind.PipeWeak, [GetBoxes, ValidateRows, BuildFromBoxes]>;
type IntersectRows = $<Kind.Pipe, [
Matrix.Columns,
$<List.Map, Type.IntersectAll>
]>;
type IntersectMatrices = $<Kind.Pipe, [
Matrix.Columns,
$<List.Map, IntersectRows>
]>;
/**
* Given a 9x9 grid of numbers, mask out all invalid Sudoku places to 'never'.
*/
export type MaskInvalidSudokuPlaces = $<Kind.Pipe, [
$<Kind.Juxt, [ValidateRows, ValidateColumns, ValidateBoxes]>,
IntersectMatrices
]>;
export {};