Upgrade to Pro — share decks privately, control downloads, hide ads and more …

あるインスタンスの取る値が
何パターンあるか数えてみるンゴ!

 あるインスタンスの取る値が
何パターンあるか数えてみるンゴ!

k-kohey

May 28, 2021
Tweet

More Decks by k-kohey

Other Decks in Programming

Transcript

  1. ͸͡Ίʹ ఴ෇͞Ε͍ͯΔιʔείʔυͷཁ໿ IUUQTUXJUUFSDPNJOBNJZTUBUVT T w 4IBSFE̍ w TIBSFEΠϯελϯε͕ৗʹଘࡏ w TIBSFEΠϯελϯεͷґଘؔ܎͸Π

    ϯελϯεͷੜ੒ޙʹղܾ w 4IBSFE̎ w TIBSFEΠϯελϯε͸ϥϯλΠϜ࣌ ʹੜ੒͞ΕΔ w ґଘؔ܎͸ΠχγϟϥΠβͰղܾ
  2. ͸͡Ίʹ ࣗ෼ͷݟղ w γϯάϧτϯʹରͯ͠TIBSFEͱ͍͏໊લΛ෇͚Δ͜ͱ͸Ұൠత w (PPHMFͷTUZMFHVJEʹ΋هड़͞Ε͍ͯΔ<> w γϯάϧτϯ͸ʮ͋ΔΫϥεͷΠϯελϯε͕͔̍ͭ͠ͳ͍ʯ͜ͱΛ୲อ͢ Δઃܭ<> w

    4IBSFE̎͸ΠϯελϯεΛෳ਺ݸ࡞ΕΔͨΊɺఆٛʹ൓͢Δ <>IUUQTHPPHMFHJUIVCJPTXJGU <>IUUQTKBXJLJQFEJBPSHXJLJ4JOHMFUPO@&&#'&#$&#
  3. ͸͡Ίʹ ࣗ෼ͷݟղ w ݁࿦ w 4IBSFE͕̍είͰ͢ʂ w ཧ༝ w 4IBSFE̎ͷར༻ऀ͸ͦΕ͕γϯάϧτϯͰ͋Δ͜ͱΛظ଴͢Δ

    w ͔͠͠ɺ࣮૷্ͦ͏ͳ͍ͬͯͳ͍ͨΊɺೝࣝͷᴥᴪ͕ੜ͡Δ w ݁Ռతʹϓϩάϥϛϯάϛε͕ى͜Δ͜ͱΛݒ೦
  4. ୅਺తσʔλܕ ఆٛ w ܕಉ࢜Λ૊Έ߹Θͤͯ࡞ΒΕΔܕͰ௚ੵܕɺ௚࿨ܕɺ͓Αͼྻڍܕ͕͋Δ<̏> w 4XJGUͰ͸ͦΕͧΕ࣍ͷΑ͏ʹදݱ͞ΕΔ w ௚ੵܕɿTUSVDU DMBTT౳ͷෳ਺ͷϓϩύςΟΛ·ͱΊ͋͛ͨ΋ͷ w

    ௚࿨ܕɿ"TTPDJBUFEWBMVFΛ࣋ͭFOVN w ྻڍܕɿ"TTPDJBUFEWBMVFΛ࣋ͨͳ͍FOVN w ௚࿨ܕͱ௚ੵܕ͕͋Ε͹ͲΜͳσʔλߏ଄Ͱ΋දݱͰ͖Δ<> w ྻڍܕ͸௚࿨ܕʹΑͬͯදݱ͞Ε͍ͯΔͱߟ͑ΒΕΔʢओ؍ʣ <̏>IUUQTRJJUBDPNL[@NPSJUBJUFNTEEBFDD <>IUUQTCMPHQFOHJONVSBUFDIFOUSZ VUN@TPVSDFGFFE
  5. ୅਺తσʔλܕ ͦΕͧΕͷ୅਺తσʔλܕ͕औΓ͏Δ஋ͷ਺ͷྫ w )VNBO͸ݸͷ஋ΛऔΓ͏Δ w BHF͸छྨͷ਺஋ΛऔΓ͏Δ w JT8PNBO͸USVFͱGBMTFͷछྨͷ஋Λ औΓ͏Δ w

    (FOEFS͸̎ݸͷ஋ΛऔΓ͏Δ w XPNBOͱNBO struct Human { let age: Int8 let isWoman: Bool } enum Gender { case woman case man }
  6. ௚ੵܕΛ࢖༻ͯ͠ίʔυ͕ෳࡶʹͳΔྫ લఏ w "OZ0QFSBUJPO͸̍̒௨Γͷ஋ΛऔΔ w #PPM͸̎௨Γͷ஋ΛऔΔ w #PPM͸̏ݸ͋Δ w 0QUJPOBM)PHF&SSPS͸̎௨Γͷ

    ஋ΛऔΔ w /JMͱ<ͳΜ͔΍͹͍> enum HogeError: Error { case ͳΜ͔΍͹͍ } struct AnyOperation { var isExecuting: Bool var isCancelled: Bool var isFinished: Bool var error: HogeError? }
  7. ௚ੵܕΛ࢖༻ͯ͠ίʔυ͕ෳࡶʹͳΔྫ ໰୊ఏٞ w JT$BODFMMFEGBMTFͷ࣌ʹFSSPS͸OJM w ࣮૷্ɺ্هͷ࢓༷Λҧ൓Ͱ͖Δ w JT&YFDVUJOHUSVF͔ͭ JT'JOJTIFEUSVFͷঢ়ଶ͸ଘࡏ͠ͳ͍ w

    ࣮૷্ɺ্هͷ࢓༷Λҧ൓Ͱ͖Δ enum HogeError: Error { case ͳΜ͔΍͹͍ } struct AnyOperation { var isExecuting: Bool var isCancelled: Bool var isFinished: Bool var error: HogeError? }
  8. ௚ੵܕΛ࢖༻ͯ͠ίʔυ͕ෳࡶʹͳΔྫ ໰୊ఏٞ w JT$BODFMMFEGBMTFͷ࣌ʹFSSPS͸ OJM w JT&YFDVUJOHUSVF͔ͭ JT'JOJTIFEUSVFͷঢ়ଶ͸ଘࡏ͠ͳ ͍ enum

    HogeError: Error { case ͳΜ͔΍͹͍ } struct AnyOperation { var isExecuting: Bool var isCancelled: Bool var isFinished: Bool var error: HogeError? } w ࢓্༷ଘࡏ͠ͳ͍ঢ়ଶΛڐ༰͢Δઃܭ ͷͨΊɺσʔλͷෆ੔߹Λى͜͞ͳ͍ ͨΊʹඞཁҎ্ͷߟྀΛڧ͍ΒΕΔ
  9. ௚ੵܕΛ࢖༻ͯ͠ίʔυ͕ෳࡶʹͳΔྫ ໰୊ఏٞ w JT$BODFMMFEUSVFͷ࣌ʹ͔͠FSSPS ͸ଘࡏ͠ͳ͍ w JT&YFDVUJOHUSVF͔ͭ JT'JOJTIFEUSVFͷঢ়ଶ͸ଘࡏ͠ͳ ͍ enum

    HogeError: Error { case ͳΜ͔΍͹͍ } struct AnyOperation { var isExecuting: Bool var isCancelled: Bool var isFinished: Bool var error: HogeError? } w ࢓্༷ଘࡏ͠ͳ͍ঢ়ଶΛڐ༰͢Δઃܭ ͷͨΊɺσʔλͷෆ੔߹Λى͜͞ͳ͍ ͨΊʹඞཁҎ্ͷߟྀΛڧ͍ΒΕΔ ຊ౰͸࣍ͷ̏ঢ়ଶ͚ͩ؅ཧ͍ͨ͠ʂʂʂ  ࣮ߦத  ਖ਼ৗऴྃ  ҟৗऴྃ  Τϥʔ͕)PHF&SSPSͷԿʹ֘౰͢Δ͔ ͳͷʹࠓ͸̍̒ঢ়ଶ΋͋Δ😭😭😭
  10. ௚ੵܕΛ࢖༻ͯ͠ίʔυ͕ෳࡶʹͳΔྫ ͦΜͳࣄ͍͍ͪͪߟ͑ͳͯ͘΋ϊϦͰॻ͚Δ͡ΌΜʁͱ͍͏໰ʹରͯ͠ w ࣮ࡍɺҎ্·Ͱઆ໌ͨ͠ࣄΛ͍͍ͪͪܭࢉ͠ͳ͕ΒίʔυΛॻ͘ࣄ͸ଟ͘ͳ͍ w งғؾͰΘ͔Δ΍Μʂ w ͔͠͠ίʔυ͕ෳࡶͩͱײͨ࣌͡ʹɺงғؾͰ͸ͳͦ͘Ε͕ͳͥෳࡶͳͷ͔Λ આ໌Ͱ͖Δͷ͸େࣄ w

    ྫ͑͹ɺίʔυϨϏϡʔͷ࣌ʹɺʮͳΜ͔೉͍͔͠Β௚ͯ͠ʯͱݴΘΕΔΑ Γɺʮߟྀͷඞཁͷແ͍Oݸͷঢ়ଶΛڐ༰͢Δઃܭʹͳ͍ͬͯΔͷͰ௚͠ ͯʯͱఆྔతʹݴΘΕΔํ͕ೲಘײ͋Δ͠ɺݐઃͳٞ࿦ʹܨ͕Δɻ