Skip to content

Commit bc0441b

Browse files
committed
simple assertSameContext
1 parent d4115b4 commit bc0441b

File tree

5 files changed

+21
-17
lines changed

5 files changed

+21
-17
lines changed

TODO.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# lattice
22

3-
`lattice/conceptBelow` & `lattice/conceptAbove`
3+
`lattice/conceptBelow`
4+
`lattice/conceptAbove`
5+
46
`LatticeLayout`
57
`layoutLattice(context)`
68

src/concept/assertSameContext.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,26 @@ import type { Concept } from "./Concept.js"
33

44
export function assertSameContext(
55
concepts: Array<Concept>,
6-
options: {
7-
who: string
8-
message: string
9-
} & Record<string, any>,
6+
options: { who: string },
107
): void {
118
if (concepts.length < 2) return
129

13-
const { who, message } = options
10+
const { who } = options
1411

15-
const [first, ...rest] = concepts
16-
const firstContext = first.context
12+
const [firstConcept, ...rest] = concepts
13+
const firstContext = firstConcept.context
1714
for (const concept of rest) {
1815
if (firstContext !== concept.context) {
19-
log(options)
16+
const message = "I expect the contexts of x and y to be the same."
17+
18+
log({
19+
who,
20+
message,
21+
concepts,
22+
first: firstConcept,
23+
offendingConcept: concept,
24+
})
25+
2026
throw new Error(`[assertSameContext by ${who}] ${message}`)
2127
}
2228
}

src/concept/conceptJoin.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@ import type { Concept } from "./Concept.js"
44
import { conceptFromAttributes } from "./conceptFromAttributes.js"
55

66
export function conceptJoin(x: Concept, y: Concept): Concept {
7-
assertSameContext([x, y], {
8-
who: "conceptJoin",
9-
message: "I expect the contexts of x and y to be the same.",
10-
})
7+
assertSameContext([x, y], { who: "conceptJoin" })
118

129
return conceptFromAttributes(x.context, setIntersection(x.intent, y.intent))
1310
}

src/concept/conceptMeet.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@ import type { Concept } from "./Concept.js"
44
import { conceptFromEntities } from "./conceptFromEntities.js"
55

66
export function conceptMeet(x: Concept, y: Concept): Concept {
7-
assertSameContext([x, y], {
8-
who: "conceptMeet",
9-
message: "I expect the contexts of x and y to be the same.",
10-
})
7+
assertSameContext([x, y], { who: "conceptMeet" })
118

129
return conceptFromEntities(x.context, setIntersection(x.extent, y.extent))
1310
}

src/lattice/conceptBelow.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import { assertSameContext } from "../concept/assertSameContext.js"
12
import type { Concept } from "../concept/Concept.js"
23

34
export function conceptBelow(x: Concept, y: Concept): boolean {
5+
assertSameContext([x, y], { who: "conceptBelow" })
46
return false
57
}

0 commit comments

Comments
 (0)