-
Notifications
You must be signed in to change notification settings - Fork 0
/
neighbourhoods.gleam
44 lines (38 loc) · 1.14 KB
/
neighbourhoods.gleam
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
//// src/neighbourhoods.gleam
////
//// Module: neighbourhoods
////
//// In this module, the Neighbourhoods type and its functions are defined.
////
//// API:
//// - Neighbourhoods
//// - get(Grid) -> Neighbourhoods
//// Internal:
//// - get_inner(Grid, Grid, Neighbourhoods) -> Neighbourhoods
// Local imports:
import cell as cel
import grid as gri
import neighbourhood as nei
// Public:
/// Neighbourhoods type definition.
/// Neighbourhoods type is represented by a list of neighbourhoods.
/// It serves usefull to separate it from the singular neighbourhood as their purpose for existence is different, that is why this is here, in a different source file.
pub type Neighbourhoods =
List(nei.Neighbourhood)
/// Get the neighbourhoods of a grid.
pub fn get(grid: gri.Grid) -> Neighbourhoods {
get_inner(gri.make_proper(grid), gri.make_transient(grid), [])
}
// Private:
/// Inner loop for getting the neighbourhoods.
fn get_inner(
grid: gri.Grid,
temp1: gri.Grid,
temp2: Neighbourhoods,
) -> Neighbourhoods {
case temp1 {
[] -> temp2
[head, ..tail] ->
get_inner(grid, tail, [nei.get(grid, cel.get_location(head)), ..temp2])
}
}