/
lesson3-optics.ts
90 lines (69 loc) · 1.76 KB
/
lesson3-optics.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import { Lens } from "monocle-ts";
const statusCodeL = Lens.fromProp<Response>()("statusCode");
const dataL = Lens.fromProp<Response>()("data");
// const timestampL = dataL.compose(Lens.fromProp<Data>()("timestamp"));
export type Horse = {
name: string;
age: number;
numberOfLegs: number;
hasTail: boolean;
};
export type Stable = {
postcode: string;
owner: Owner | null;
horse: Horse;
};
export type Owner = {
name: string;
age: number;
};
export type Data = {
timestamp: number;
stable: Stable;
};
export type Response = {
statusCode: 201 | 400 | 500;
data: Data;
};
export const sampleResponse: Response = {
statusCode: 201,
data: {
timestamp: 100,
stable: {
postcode: "N1 1SL",
owner: {
name: "Ultimate Steve",
age: 1000
},
horse: {
name: "CHAMPION",
age: 10,
numberOfLegs: 3,
hasTail: true
}
}
}
};
// getters
// statusCode :: number
export const statusCode = statusCodeL.get(sampleResponse);
// timestamp: number
export const timestamp = undefined as any;
// postcode :: string
export const postcode = undefined as any;
// horseLegs :: number
export const horseLegs = undefined as any;
// horseName :: string
export const horseName = undefined as any;
// setters
// responseWith400StatusCode :: Response
export const responseWith400StatusCode = undefined as any;
// responseWithRemovedTail :: Response
export const responseWithRemovedTail = undefined as any;
// responseWithAdditionalLeg :: Response
export const responseWithAdditionalLeg = undefined as any;
// over
// horseBirthday :: Response -> Response
export const horseBirthday = undefined as any;
// mapHorse :: (Horse -> Horse) -> Response -> Response
export const mapHorse = undefined as any;