Last active
July 23, 2017 04:22
-
-
Save codecalypso/b21d8ac668885c38c23a82225d5963b4 to your computer and use it in GitHub Desktop.
Revisions
-
codecalypso revised this gist
Jul 23, 2017 . 1 changed file with 13 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -74,4 +74,16 @@ const result = R.partition(highRating, schools) const path = lensPath(["a","b", "c"]) const append = (data) => data.concat(4) over(path, append)(state) //{"a": {"b": {"c": [1, 2, 3, 4]}}} let EmptylaundryBasket = [] let laundryBasket = ["towels", "pants", "socks"] var fn = R.cond([ [R.isEmpty, R.always('Work on art project')], [R.complement(isEmpty), R.always('Head to nearest laundromat')], [R.T, always('Nothing to see here')] ]); fn(laundryBasket) //Head to nearest laundromat -
codecalypso revised this gist
Jun 29, 2017 . 1 changed file with 15 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -60,4 +60,18 @@ const result = R.partition(highRating, schools) //[[{"name": "Lane", "rating": 10, "type": "public"}, {"name": "Jones", "rating": 10, "type": "public"}, {"name": "Payton", "rating": 10, "type": "public"}], //[{"name": "King", "rating": 6, "type": "public"}, {"name": "Kenwood", "rating": 6, "type": "public"}, {"name": "Bogan", "rating": 3, "type": "public"}]] const state ={a: { b:{ c: [1,2,3] } } } const path = lensPath(["a","b", "c"]) const append = (data) => data.concat(4) over(path, append)(state) //{"a": {"b": {"c": [1, 2, 3, 4]}}} -
codecalypso revised this gist
May 14, 2017 . 1 changed file with 8 additions and 8 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -12,19 +12,19 @@ const person = { const flens = R.lens(R.prop("firstName"), R.assoc("firstName")) const result = R.view(flens, person) //"Bruce" const superStars = [ { name: "Beyonce", grammys: 22, birthYear: 1981 }, { name: "Britney Spears", grammys: 1, birthyear: 1981}, { name: "James Brown", grammys: 6, birthYear: 1933}, { name: "Michal Jackson", grammys: 13, birthYear: 1958}, { name: "Prince", grammys: 8, birthYear: 1958}, { name: "Janet Jackson", grammys: 5, birthYear: 1966} ] const names = superStars.map(n => ({name: n.name})) const names = superStars.map(n => R.pick(['name'], n)) //[{"name":"Beyonce"},{"name":"Britney Spears"},{"name":"James Brown"},{"name":"Michal Jackson"},{"name":"Prince"},{"name":"Janet Jackson”}] const superStars = [ { name: "Beyonce", grammys: 22, birthYear: 1981 }, -
codecalypso revised this gist
May 14, 2017 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,7 @@ var xLens = R.lensProp('x'); R.view(xLens, {x: 'Jerry', y: 'Tom'}); //“Jerry" R.set(xLens, "Tweety", {x: 1, y: "Tom"}); //{"x": "Tweety", "y": "Tom"} R.over(xLens, R.toUpper, {x: "jerry", y: "Tom"}); // {"x": "JERRY", "y": "Tom”} const person = { @@ -35,7 +35,7 @@ const superStars = [ { name: "Janet Jackson", grammys: 5, birthYear: 1966} ] //[{"name":"Beyonce","grammys":22,"birthYear":1981},{"name":"Michal Jackson","grammys":13,"birthYear":1958},{"name":"Prince","grammys":8,"birthYear":1958},{"name":"James Brown","grammys":6,"birthYear":1933},{"name":"Janet Jackson","grammys":5,"birthYear":1966},{"name":"Britney Spears","grammys":1,"birthyear":1981}] const beforeEighty = year => year.birthYear < 1980 -
codecalypso created this gist
May 14, 2017 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,63 @@ var xLens = R.lensProp('x'); R.view(xLens, {x: 'Jerry', y: 'Tom'}); //“Jerry" R.set(xLens, "Tweety", {x: 1, y: "Tom"}); //{"x": "Tweety", "y": "Tom"} R.over(xLens, R.toUpper, {x: "jerry", y: "Tom"}); // {"x": "JERRY", "y": "Tom”} const person = { firstName: "Bruce", lastName: "Wayne" } const flens = R.lens(R.prop("firstName"), R.assoc("firstName")) const result = R.view(flens, person) //"Bruce" const superStars = [ { name: "Beyonce", grammyCount: 5, birthYear: 1982 }, { name: "Britney Spears", grammyCount: 0, birthyear: 1980}, { name: "James Brown", grammyCount: 0, birthYear: 0}, { name: "Michal Jackson", grammyCount: 0, birthYear: 0}, { name: "Prince", grammyCount: 0, birthYear: 0}, { name: "Cher", grammyCount: 0, birthYear: 0} ] const names = superStars.map(n => ({name: n.name})) const names = superStars.map(n => R.pick(['name'], n)) //[{"name":"Beyonce"},{"name":"Britney Spears"},{"name":"James Brown"},{"name":"Michal Jackson"},{"name":"Prince"},{"name":"Cher”}] const superStars = [ { name: "Beyonce", grammys: 22, birthYear: 1981 }, { name: "Britney Spears", grammys: 1, birthyear: 1981}, { name: "James Brown", grammys: 6, birthYear: 1933}, { name: "Michal Jackson", grammys: 13, birthYear: 1958}, { name: "Prince", grammys: 8, birthYear: 1958}, { name: "Janet Jackson", grammys: 5, birthYear: 1966} ] [{"name":"Beyonce","grammys":22,"birthYear":1981},{"name":"Michal Jackson","grammys":13,"birthYear":1958},{"name":"Prince","grammys":8,"birthYear":1958},{"name":"James Brown","grammys":6,"birthYear":1933},{"name":"Janet Jackson","grammys":5,"birthYear":1966},{"name":"Britney Spears","grammys":1,"birthyear":1981}] const beforeEighty = year => year.birthYear < 1980 //[{"birthYear": 1933, "grammys": 6, "name": "James Brown"}, {"birthYear": 1958, "grammys": 13, "name": "Michal Jackson"}, {"birthYear": 1958, "grammys": 8, "name": "Prince"}, {"birthYear": 1966, "grammys": 5, "name": "Janet Jackson”}] const eightyAndAfter = R.reject(beforeEighty, superStars) //[{"birthYear": 1981, "grammys": 22, "name": "Beyonce"}, {"birthyear": 1981, "grammys": 1, "name": "Britney Spears”}] const schools = [ { name: "King", rating: 6, type: "public"}, { name: "Kenwood", rating: 6, type: "public"}, { name: "Lane", rating: 10, type: "public"}, { name: "Bogan", rating: 3, type: "public"}, { name: "Jones", rating: 10, type: "public"}, { name: "Payton", rating: 10, type: "public"}, ] const highRating = score => score.rating > 8 const result = R.partition(highRating, schools) //[[{"name": "Lane", "rating": 10, "type": "public"}, {"name": "Jones", "rating": 10, "type": "public"}, {"name": "Payton", "rating": 10, "type": "public"}], //[{"name": "King", "rating": 6, "type": "public"}, {"name": "Kenwood", "rating": 6, "type": "public"}, {"name": "Bogan", "rating": 3, "type": "public"}]]