Totality
f = x => y
fxy

type Divide = (a:number, b: number) => number
const divide: Divide = (a,b) => b !== 0 ? a/b : NaN

0divide
3

1.
2.
3. ()

1(20)

2 EitherOption使
type Divide = (a:number, b: number) => number | undefined
const divide: Divide = (a,b) => b !== 0 ? a/b : undefined
divide

30
import z from "zod"
const NonZeroNumber = z.number().refine(v => v !== 0)
type NonZeroNumber = z.infer<typeof NonZeroNumber>
type Divide = (a:number, b: NonZeroNumber) => number
const divide: Divide = (a,b) => a/b
divide(6, NonZeroNumber.parse(3)) // -> 2
divide(6, NonZeroNumber.parse(0)) // Parse Error
divide(6, 3) // Compile Error

32
()Shotgun Parsing

3Domain Modeling Made Functional

Person
type Person = {
lastName: string;
firstName: string;
postalCd: string;
prefectureCd: string;
address1: string;
address2: string;
birthday: Date;
guardians: {
lastname: string;
firstName: string;
relationship: Relationship;
} []
}
Person payChildAllowance
function payChildAllowance(person: Person, amount: BigDecimal) {
if (calcAge(person.birthday) >= 18) {
throw new Error(``)
}
person.guardians.length > 0 && saveAllowance(person.guardians[0], amount);
}
payChildAllowance payChildAllowance payChildAllowance

payChildAllowance
type UnderagePerson = {
lastName: string;
//
birthday: Date;
guardians: {
lastname: string;
firstName: string;
relationship: Relationship;
} []
}
type OveragePerson = {
lastName: string;
//
birthday: Date;
}
type Person = OveragePerson | UnderagePerson
function payChildAllowance(person: UnderagePerson, amount: BigDecimal) {
person.guardians.length > 0 && saveAllowance(person.guardians[0], amount);
}
payChildAllowance

Person? Intersection
type OveragePerson = {
lastName: string;
//
birthday: Date;
}
type UnderagePerson = OveragePerson & {
guardians: {
lastName: string;
firstName: string;
relationship: Relationship;
}[]
}
UnderagePersonOverage PersonOveragePerson

Domain Modeling Made Functional
type PersonName = {
lastName: string;
firstName: string;
}
type PostalAddress = {
postalCd: string;
prefectureCd: string;
address1: string;
address2: string;
}
type Birthday = {
birthday: Date;
}
type Guardian = {
name: PersonName;
relationship: Relationship;
}
type UnderagePerson = {
name: PersonName;
address: PostalAddress;
birthday: Birthday;
}
type OveragePerson = {
name: PersonName;
address: PostalAddress;
birthday: Birthday;
guardians: Guardian[];
}

/

?
>@MinoDriven:
>

const  = (noodle: UncookedNoodle, hardness: ) => CookedNoodle