Created
June 2, 2020 06:55
-
-
Save hardyscc/da64cc0c1375a8d75f18d5da6d8de2aa to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output: