Skip to content

Instantly share code, notes, and snippets.

@hardyscc
Created June 2, 2020 06:55
Show Gist options
  • Save hardyscc/da64cc0c1375a8d75f18d5da6d8de2aa to your computer and use it in GitHub Desktop.
Save hardyscc/da64cc0c1375a8d75f18d5da6d8de2aa to your computer and use it in GitHub Desktop.
import R from "ramda";
type Person = {
id: number;
name: string;
type: string;
};
function main() {
const array: Person[] = [
{ id: 0, name: "_", type: "y" },
{ id: 1, name: "a", type: "x" },
{ id: 2, name: "b", type: "x" },
{ id: 3, name: "c", type: "y" },
{ id: 4, name: "d", type: "x" },
];
const rejectByName = R.reject<Person, "array">(R.propEq("name", "_"));
const groupByType = R.groupBy<Person>(R.prop("type"));
const composeFun = R.compose(groupByType, rejectByName);
console.log(composeFun(array));
}
main();
@hardyscc
Copy link
Author

hardyscc commented Jun 2, 2020

Output:

{
 x: [
   { id: 1, name: 'a', type: 'x' },
   { id: 2, name: 'b', type: 'x' },
   { id: 4, name: 'd', type: 'x' }
 ],
 y: [ { id: 3, name: 'c', type: 'y' } ]
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment