Skip to content

Instantly share code, notes, and snippets.

View uriell's full-sized avatar
:shipit:
Lurking

Uriell uriell

:shipit:
Lurking
View GitHub Profile
class Counter extends React.Component {
state = { count: 0 }
increment() {
this.setState(currentState => ({ count: currentState.count + 1 }));
}
render() {
const { count } = this.state;
@uriell
uriell / float.monad.ts
Last active February 6, 2024 19:32
Float (monad version, functional)
interface IFloat {
value: number;
precision: number;
getPrecision(multiplier?: number): number;
toString(): string;
toValue(): number;
toWholeNumber(): IFloat;
floor(): IFloat;
roundDown(roundingFactor: number): IFloat;
divide(input: number): IFloat;
@uriell
uriell / float.class.ts
Created February 6, 2024 19:33
Float (class version, monad-like)
class SafeFloat {
value: number;
precision: number;
constructor(value: number, precision: number = 1) {
this.value = value;
this.precision = precision;
}
getPrecision(multiplier: number = 1) {