Skip to content

Commit b7bef1d

Browse files
committed
chore: make some utils universal
1 parent cf3e2a8 commit b7bef1d

File tree

3 files changed

+31
-27
lines changed

3 files changed

+31
-27
lines changed

.grit/patterns/universal/blocks.grit

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
language universal
2+
3+
// Implementation
4+
function group_blocks($target) {
5+
$blocks = [],
6+
$target <: some bubble($blocks, $block, $block_tail) $current where {
7+
if ($block <: undefined) {
8+
$block = [$current],
9+
$block_tail = $current,
10+
} else {
11+
// Are we right after the same block?
12+
if ($current <: after $block_tail) {
13+
$block += $current,
14+
$block_tail = $current
15+
} else {
16+
// Insert the previous block into the list
17+
$blocks += $block,
18+
$block = [$current],
19+
$block_tail = $current
20+
}
21+
}
22+
},
23+
// Insert final block
24+
if (not $block <: undefined) {
25+
$blocks += $block
26+
},
27+
return $blocks
28+
}
29+

.grit/patterns/js/lists.grit renamed to .grit/patterns/universal/lists.grit

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
language js
1+
language universal
22

33
// Concat two lists together
44
function concat($list_a, $list_b) {

.grit/patterns/js/blocks.md renamed to .grit/patterns/universal/use_blocks.md

+1-26
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,7 @@
33
The `group_blocks` function takes a `target` list and returns a list of lists, where each sublist is a block of items that are adjacent to each other in the original program.
44

55
```grit
6-
// Implementation
7-
function group_blocks($target) {
8-
$blocks = [],
9-
$target <: some bubble($blocks, $block, $block_tail) $current where {
10-
if ($block <: undefined) {
11-
$block = [$current],
12-
$block_tail = $current,
13-
} else {
14-
// Are we right after the same block?
15-
if ($current <: after $block_tail) {
16-
$block += $current,
17-
$block_tail = $current
18-
} else {
19-
// Insert the previous block into the list
20-
$blocks += $block,
21-
$block = [$current],
22-
$block_tail = $current
23-
}
24-
}
25-
},
26-
// Insert final block
27-
if (not $block <: undefined) {
28-
$blocks += $block
29-
},
30-
return $blocks
31-
}
6+
language js
327
338
// Usage example
349
file($body) where {

0 commit comments

Comments
 (0)