Back to packages list

Vals using ramda

Description from the NPM package:
A practical functional library for JavaScript programmers.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import { msWeek } from "https://esm.town/v/stevekrouse/msWeek?v=3";
import { gitlabUserContributionEvents } from "https://esm.town/v/rwev/gitlabUserContributionEvents";
export async function gitlabWeeklySummary() {
const R = await import("npm:ramda");
const userEvents = await gitlabUserContributionEvents(
Date.now() - msWeek
);
return R.applySpec({
commits: R.pipe(
R.filter(R.pipe(R.path(["push_data", "commit_count"]), R.isNotNil)),
R.map(R.path(["push_data", "commit_count"])),
R.filter(R.isNotNil),
R.sum
),
})(userEvents);
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
export type AstronomyPoint = {
moon_illumination: string; // "78",
moon_phase: string; // "Waxing Gibbous",
moonrise: string; //"04:34 PM",
moonset: string; //"04:59 AM",
sunrise: string; // "06:38 AM",
sunset: string; //"08:40 PM",
date: string; // "2023-05-01"
};
export type AstronomyData = AstronomyPoint[];
export async function wttrAstronomyData(
wttrJson: any // return of @me.wttrJson
): Promise<AstronomyData> {
const R = await import("npm:ramda");
return R.pipe(R.map((w) => ({ date: w.date, ...w.astronomy[0] })))(
wttrJson.weather
);
}

ramda

ramda is a module like lodash or underscore but with a much heavier emphasis on functional programming. It lets you do the same kind of things but in a much 🌶️ spicier, 💪 more macho, 🤔 sometimes confusing style. I was really into this module in my late 20s.

Readme
1
2
3
4
export let ramdaExample = (async () => {
const R = await import("npm:ramda");
return R.ap([R.concat("tasty "), R.toUpper], ["pizza", "salad"]);
})();
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
import { snakeToTitleCase } from "https://esm.town/v/rwev/snakeToTitleCase";
import { wrapInHTMLElements } from "https://esm.town/v/rwev/wrapInHTMLElements";
export async function wttrAstronomyToHTMLTable(
jsonReport: any
): Promise<string> {
let html = ``;
const R = await import("npm:ramda");
const wrapFn = R.curry(wrapInHTMLElements);
const headers = [
"date",
"moon_illumination",
"moon_phase",
"moonrise",
"moonset",
"sunrise",
"sunset",
];
html += R.pipe(
R.map(snakeToTitleCase),
R.map(wrapFn("td")),
R.join(""),
wrapFn(["tr", "thead"])
)(headers);
html += R.pipe(
R.map((point) => R.map(R.flip(R.prop)(point))(headers)),
R.map(R.map(wrapFn("td"))),
R.map(R.join("")),
R.map(wrapFn("tr")),
R.join("")
)(jsonReport);
return wrapFn("table", html);
}
1
Next