Skip to content

Commit

Permalink
use concat_map instead of concat . map
Browse files Browse the repository at this point in the history
  • Loading branch information
dm0n3y committed Feb 17, 2025
1 parent 1ed310f commit bd66334
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/stds/Lists.re
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ module Framed = {
module Syntax = {
let (let+) = (xs, f) => List.map(f, xs);
let (and+) = Base.List.cartesian_product;
let ( let* ) = (xs, f) => List.concat(List.map(f, xs));
let ( let* ) = (xs, f) => List.concat_map(f, xs);
let return = single;
};

Expand Down
19 changes: 8 additions & 11 deletions src/web/util/Svgs.re
Original file line number Diff line number Diff line change
Expand Up @@ -189,16 +189,15 @@ module OrthogonalPolygon = {
};

path
|> List.map(
|> List.concat_map(
fun
| Path.H_({dx}) => Path.[H_({dx: dx *. 0.5}), H_({dx: dx *. 0.5})]
| V_({dy}) => [V_({dy: dy *. 0.5}), V_({dy: dy *. 0.5})]
| cmd => [cmd],
)
|> List.flatten
|> Lists.rotate
|> Lists.disjoint_pairs
|> List.map(((cmd1: Path.cmd, cmd2: Path.cmd)) => {
|> List.concat_map(((cmd1: Path.cmd, cmd2: Path.cmd)) => {
switch (cmd1, cmd2) {
| (H_({dx}), V_({dy})) =>
let (rx, ry) = max_radii((rx, ry), (dx, dy));
Expand Down Expand Up @@ -234,8 +233,7 @@ module OrthogonalPolygon = {
];
| _ => [cmd1, cmd2]
}
})
|> List.flatten;
});
};

let is_left_side = (edge: linked_edge): bool => {
Expand Down Expand Up @@ -308,7 +306,7 @@ module OrthogonalPolygon = {
let vertical_contour_edges = (rects: list(Rect.t)): list(linked_edge) => {
let sorted_vertical_sides: list(linked_edge) =
rects
|> List.map((Rect.{min, width, height}) => {
|> List.concat_map((Rect.{min, width, height}) => {
let max_x = min.x +. width;
let max_y = min.y +. height;
let max = Point.{x: max_x, y: max_y};
Expand All @@ -321,7 +319,6 @@ module OrthogonalPolygon = {
{src: max_min, dst: max, next: None},
];
})
|> List.flatten
|> List.sort((v1, v2) =>
if (v1.src.x < v2.src.x) {
(-1);
Expand All @@ -344,8 +341,9 @@ module OrthogonalPolygon = {

let segment_tree =
rects
|> List.map((Rect.{min, height, _}) => [min.y, min.y +. height])
|> List.flatten
|> List.concat_map((Rect.{min, height, _}) =>
[min.y, min.y +. height]
)
|> SegmentTree.mk;

sorted_vertical_sides
Expand Down Expand Up @@ -395,8 +393,7 @@ module OrthogonalPolygon = {

// join vertical contour edges via horizontal edges
vertical_contour_edges
|> List.map(v => [(false, v), (true, v)])
|> List.flatten
|> List.concat_map(v => [(false, v), (true, v)])
// sort endpoints by y coordinate, then x coordinate
|> List.sort(((is_src1, v1), (is_src2, v2)) => {
let pt1 = is_src1 ? v1.src : v1.dst;
Expand Down

0 comments on commit bd66334

Please sign in to comment.