kaidouji85
May 03, 2016
290

# Ramdaで手軽に関数型言語を始めよう

May 03, 2016

## Transcript

8. ### forΛ࢖ͬͨ΍Γํ let postData = []; for (let i in todo)

{ if(todo[i].isChanged) { postData.push(convertData(todo[i])); } }

11. ### RamdaΛ࢖ͬͯಉ͡ॲཧΛॻ͘ let chanegedList = R.filter(data=>data.isChanged, todo); let postData = R.map(convertData,

chanegedList); ωετ͕ਂ͘ͳͯ͘γϯϓϧʹ ͔͠΋ɺม਺ͷ஋͸୅ೖ͔ͯ͠Β  มΘͬͯͳ͍

17. ### ίʔυͱͷରԠ let chanegedList = R.filter(data=>data.isChanged, todo); let postData = R.map(convertData,

chanegedList); filter มߋͨ͠ίʔυ͚ͩ࢒͢
18. ### ίʔυͱͷରԠ let chanegedList = R.filter(data=>data.isChanged, todo); let postData = R.map(convertData,

chanegedList); ࢒͢৚݅͸ɺؔ਺ͱͯ͠ఆٛ͢Δ
19. ### ίʔυͱͷରԠ let chanegedList = R.filter(data=>data.isChanged, todo); let postData = R.map(convertData,

chanegedList); ͜͏͍͏ͷΛؔ਺ܕݴޠͰ͸ϥϜμࣜͱ͍͏
20. ### ίʔυͱͷରԠ let chanegedList = R.filter(data=>data.isChanged, todo); let postData = R.map(convertData,

chanegedList); ؔ਺ͷϑΥʔϚοτ͸ҎԼͷ௨Γ ୈҰҾ਺ɿɹ഑ྻཁૉͷ஋ ໭Γ஋ɹɿɹboolean(trueͰ࢒͢)
21. ### ίʔυͱͷରԠ let chanegedList = R.filter(data=>data.isChanged, todo); let postData = R.map(convertData,

chanegedList); ͜ͷྫͰ͸isChanged͕trueͳΒ มߋ͞Εͨͱݟͳ͍ͯ͠Δ ɹˣ มߋ͞Εͨཁૉ͚ͩΛ࢒͢ͱ͍͏ҙຯʹͳΔ
22. ### ίʔυͱͷରԠ let chanegedList = R.filter(data=>data.isChanged, todo); let postData = R.map(convertData,

chanegedList); ͜͜ʹFILTERର৅ͷ഑ྻΛࢦఆ͢Δ
23. ### ίʔυͱͷରԠ let chanegedList = R.filter(data=>data.isChanged, todo); let postData = R.map(convertData,

chanegedList); MAP API༻ʹσʔλม׵
24. ### ίʔυͱͷରԠ let chanegedList = R.filter(data=>data.isChanged, todo); let postData = R.map(convertData,

chanegedList); ͜͜ʹσʔλม׵͢Δؔ਺Λࢦఆ͢Δ
25. ### ίʔυͱͷରԠ let chanegedList = R.filter(data=>data.isChanged, todo); let postData = R.map(convertData,

chanegedList); ؔ਺ͷϑΥʔϚοτ͸ҎԼͷ௨Γ ୈҰҾ਺ɿɹ഑ྻཁૉͷ஋ ໭Γ஋ɹɿɹม׵ޙͷσʔλ
26. ### ίʔυͱͷରԠ let chanegedList = R.filter(data=>data.isChanged, todo); let postData = R.map(convertData,

chanegedList); ͜ͷྫͰ͸convertDataͰ σʔλม׵͢ΔͷͰɺ ͜ΕΛͦͷ··ࢦఆ͢Δ
27. ### ίʔυͱͷରԠ let chanegedList = R.filter(data=>data.isChanged, todo); let postData = R.map(convertData,

chanegedList); ͜͜ʹMAPର৅ͷ഑ྻΛࢦఆ͢Δ

31. ### ·ͣ͸Promise.allͰ·ͱΊͯ ΤϥʔνΣοΫ·Ͱ͸ࢥ͍ͭ͘ let promiseList = R.map(todo => isError(todo), todos); Promise.all(promiseList).then(resps

=> { }); ˞isError͸PromiseΛฦ͠·͢
32. ### ·ͣ͸Promise.allͰ·ͱΊͯ ΤϥʔνΣοΫ·Ͱ͸ࢥ͍ͭ͘ let promiseList = R.map(todo => isError(todo), todos); Promise.all(promiseList).then(resps

=> { }); TODOͷ֤Ϩίʔυ͝ͱʹ ΤϥʔνΣοΫAPIΛ࣮ߦ ˞isError͸PromiseΛฦ͠·͢
33. ### ·ͣ͸Promise.allͰ·ͱΊͯ ΤϥʔνΣοΫ·Ͱ͸ࢥ͍ͭ͘ let promiseList = R.map(todo => isError(todo), todos); Promise.all(promiseList).then(resps

=> { }); TODOϦετΛΤϥʔνΣοΫ APIͷPromiseϦετʹมߋ ˞isError͸PromiseΛฦ͠·͢
34. ### ˞isError͸PromiseΛฦ͠·͢ ·ͣ͸Promise.allͰ·ͱΊͯ ΤϥʔνΣοΫ·Ͱ͸ࢥ͍ͭ͘ let promiseList = R.map(todo => isError(todo), todos);

Promise.all(promiseList).then(resps => { }); ͍ͭ͜ΛPromise.allʹ ౤͛ͯฒྻ࣮ߦ͢Δ
35. ### Ͱ΋ɺTODOຊମͱΤϥʔνΣοΫ͕ผʑͷ഑ྻ ͔ͩΒɺॲཧ͕൥ࡶʹͳΓͦ͏ let promiseList = R.map(todo => isError(todo), todos); Promise.all(promiseList).then(resps

=> { }); TODOຊମ ΤϥʔνΣοΫ݁Ռ

40. ### ίʔυͰॻ͘ͱ͜͏ͳΓ·͢ let promiseList =   R.map(todo => isError(todo), todos); Promise.all(promiseList).then(resps

=> { let errorData = R.pipe( R.zip, R.filter(item => item[1].isError), R.map(item => getErrorData(item[0].id)) )(todos, resps); });
41. ### ίʔυͰॻ͘ͱ͜͏ͳΓ·͢ let promiseList =   R.map(todo => isError(todo), todos); Promise.all(promiseList).then(resps

=> { let errorData = R.pipe( R.zip, R.filter(item => item[1].isError), R.map(item => getErrorData(item[0].id)) )(todos, resps); }); R.pipeͰෳ਺ͷॲཧΛܨ͔͚͛ͯ·͢
42. ### ίʔυͰॻ͘ͱ͜͏ͳΓ·͢ let promiseList =   R.map(todo => isError(todo), todos); Promise.all(promiseList).then(resps

=> { let errorData = R.pipe( R.zip, R.filter(item => item[1].isError), R.map(item => getErrorData(item[0].id)) )(todos, resps); }); ͜͜ʹ࠷ॳͷॲཧʹ౉͢Ҿ਺Λࢦఆ
43. ### ίʔυͰॻ͘ͱ͜͏ͳΓ·͢ let promiseList =   R.map(todo => isError(todo), todos); Promise.all(promiseList).then(resps

=> { let errorData = R.pipe( R.zip, R.filter(item => item[1].isError), R.map(item => getErrorData(item[0].id)) )(todos, resps); }); ࠓճ͸TODOຊମͱ ΤϥʔνΣοΫ݁Ռ
44. ### ίʔυͰॻ͘ͱ͜͏ͳΓ·͢ let promiseList =   R.map(todo => isError(todo), todos); Promise.all(promiseList).then(resps

=> { let errorData = R.pipe( R.zip, R.filter(item => item[1].isError), R.map(item => getErrorData(item[0].id)) )(todos, resps); }); TODOຊମͱΤϥʔνΣοΫ݁ՌΛ߹ମ
45. ### ίʔυͰॻ͘ͱ͜͏ͳΓ·͢ let promiseList =   R.map(todo => isError(todo), todos); Promise.all(promiseList).then(resps

=> { let errorData = R.pipe( R.zip, R.filter(item => item[1].isError), R.map(item => getErrorData(item[0].id)) )(todos, resps); }); R.zipͷ݁Ռ͕͍ͭ͜ͷॲཧର৅ʹͳΔ
46. ### ίʔυͰॻ͘ͱ͜͏ͳΓ·͢ let promiseList =   R.map(todo => isError(todo), todos); Promise.all(promiseList).then(resps

=> { let errorData = R.pipe( R.zip, R.filter(item => item[1].isError), R.map(item => getErrorData(item[0].id)) )(todos, resps); }); item[0] : todoຊମ item[1] : ΤϥʔνΣοΫ݁Ռ
47. ### ίʔυͰॻ͘ͱ͜͏ͳΓ·͢ let promiseList =   R.map(todo => isError(todo), todos); Promise.all(promiseList).then(resps

=> { let errorData = R.pipe( R.zip, R.filter(item => item[1].isError), R.map(item => getErrorData(item[0].id)) )(todos, resps); }); ͜ͷ৚݅͸Τϥʔ͕͋Δ Ϩίʔυ͚ͩΛ࢒͢ͱ͍͏ҙຯ
48. ### ίʔυͰॻ͘ͱ͜͏ͳΓ·͢ let promiseList =   R.map(todo => isError(todo), todos); Promise.all(promiseList).then(resps

=> { let errorData = R.pipe( R.zip, R.filter(item => item[1].isError), R.map(item => getErrorData(item[0].id)) )(todos, resps); }); ΍ͬͺΓR.filterͷ݁Ռ͕ೖྗʹͳΔ
49. ### ίʔυͰॻ͘ͱ͜͏ͳΓ·͢ let promiseList =   R.map(todo => isError(todo), todos); Promise.all(promiseList).then(resps

=> { let errorData = R.pipe( R.zip, R.filter(item => item[1].isError), R.map(item => getErrorData(item[0].id)) )(todos, resps); }); ͜͜ͰΤϥʔσʔλʹม׵͢Δ
50. ### ίʔυͰॻ͘ͱ͜͏ͳΓ·͢ let promiseList =   R.map(todo => isError(todo), todos); Promise.all(promiseList).then(resps

=> { let errorData = R.pipe( R.zip, R.filter(item => item[1].isError), R.map(item => getErrorData(item[0].id)) )(todos, resps); }); Τϥʔσʔλͷ഑ྻ͕֨ೲ͞ΕΔ

53. ### ެࣜαΠτ ϓϩδΣΫτϖʔδ  http:/ /ramdajs.com/0.21.0/index.html υΩϡϝϯτ  http:/ /ramdajs.com/0.21.0/docs/ Try Ramda (ϒϥ΢βͰRamda͕ࢼͤ·͢)

http:/ /ramdajs.com/repl/?v=0.21.0