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

改めて学ぶContracts

tommykw
August 24, 2019

 改めて学ぶContracts

tommykw

August 24, 2019
Tweet

More Decks by tommykw

Other Decks in Programming

Transcript

  1. ˞ʮӾཡ਺ʯʮར༻ऀ਺ʯ͸ϝσΟΞͱΞϓϦͷ߹ܭ஋ʢ೥݄݄ͷฏۉ஋ʣ ˞ʮϚϚ޲͚/PΞϓϦʯ͸೥݄Πϯςʔδௐ΂ɹௐࠪର৅ɿ೛৷தʙ̎ࡀ̌ϲ݄ͷࢠڙΛ࣋ͭঁੑ O  Λநग़ ˞*OTUBHSBNͷϑΥϩϫʔ਺ɺ'BDFCPPLͷ͍͍Ͷ਺ɺ-*/&ͷͱ΋ͩͪ਺ͷ߹ܭ஋ ೥݄࣌఺  ϚϚϦ ΞϓϦɾ8FC

    4/4 *OTUBHSBNɾ-*/&ɾ'BDFCPPL هࣄ ϚϚಉ࢜Ͱ೰ΈΛ૬ஊ͠߹͏2"ίϛϡχςΟΛத৺ʹ ϢʔβʔΛ֦େ͍ͯ͠·͢ ʮϚϚϦʯͰϢʔβʔಉ͕࢜ ͲΜͲΜܨ͕͍ͬͯ·͢ ϚϚͷੜ׆ʹ໾ཱͭهࣄΛ ෯޿͍δϟϯϧͰ഑৴͍ͯ͠·͢ ϚϚ޲͚/P̍ΞϓϦʹબग़  ਓͷϚϚ͕બͿʮݱࡏ࢖͍ͬͯΔΞϓϦʯʹ ͯɺ߲໨ ଞͷϚϚʹΦεεϝ͍ͨ͠ɺೝ஌౓ɺ
 ར༻཰ɺརศੑɺ޷ײ౓ Ͱ̍ҐΛ֫ಘ͠·ͨ͠ هࣄ਺ 6,000 هࣄҎ্ ྦྷܭϑΝϯ਺ ໿ 85 ສਓ ˞ ݄ؒӾཡ਺ ໿ 1.5ԯճ ˞ ݄ؒར༻ऀ਺ ໿ 650ສਓ ˞ ˞ l೰ΈzͱzڞײzΛ࣠ʹϚϚʹدΓఴ͍ ΞϓϦɾ8FCɾ4/4ͱଟ֯తʹαʔϏεΛల։͍ͯ͠·͢
  2. ͲΜͳػೳʁ w ίϯύΠϥʹҰ෦৚݅ΛՃ͑Δ͜ͱ͕Ͱ͖Δ w ϥϯλΠϜͰ͸ͳ͘ɺίϯύΠϧ࣌ʹద༻ w ੩తղੳͰ͖Δ w ؔ਺ʹద༻Ͱ͖Δ w

    Ͱಋೖ͞Εͨ&YQFSJNFOUBMͳػೳ w ݱ࣌఺Ͱͷߏจ͸&BSMZ1SPUPUZQF w ͔͠͠4UEMJCͰ΋ଟ਺ར༻͞Ε͍ͯΔ w %4-ܖ໿Λ݁Ϳ͜ͱͰ৚݅ΛࢦఆͰ͖Δ
  3. ೥ද ,PUMJO ,PUMJO$POG։࠵ ͷൃදָ͕͠Έʂ ෆ۩߹मਖ਼ ,5 ,5 ,5ͳͲ ෆ۩߹मਖ਼ ,5

    ,5 $POUSBDUTϦϦʔεʂ ෆ۩߹मਖ਼ ,5 ,5 ,5ͳͲ ,PUMJO ,PUMJO ,PUMJO ,PUMJO ,PUMJO
  4. είʔϓؔ਺Ͱ΋࠾༻͞Ε͍ͯΔ public inline fun <R> run( block: () -> R

    ): R { contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) } return block() } public inline fun <T> T.apply( block: T.() -> Unit ): T { contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) } block() return this } public inline fun <T, R> with( receiver: T, block: T.() -> R ): R { contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) } return receiver.block() } public inline fun <T, R> T.let( block: (T) -> R ): R { contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) } return block(this) } SVO XJUI BQQMZ MFU
  5. είʔϓؔ਺Ͱ΋࠾༻͞Ε͍ͯΔ public inline fun <R> run( block: () -> R

    ): R { contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) } return block() } public inline fun <T> T.apply( block: T.() -> Unit ): T { contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) } block() return this } public inline fun <T, R> with( receiver: T, block: T.() -> R ): R { contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) } return receiver.block() } public inline fun <T, R> T.let( block: (T) -> R ): R { contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) } return block(this) } SVO XJUI BQQMZ MFU
  6. w 3FTVMUHFU0S&MTF w 3FTVMUGPME w 3FTVMUNBQ w 3FTVMUSFDPWFS w 3FTVMUPO'BJMVSF

    w 3FTVMUPO4VDDFTT w SFRVJSF w SFRVJSF/PU/VMM w DIFDL w DIFDL/PU/VMM w FSSPS 4UEMJCͰͷར༻ঢ়گ w SVO w XJUI w BQQMZ w BMTP w MFU w UBLF*G w UBLF6OMFTT w SFQFBU w NFBTVSF5JNF w NFBTVSF5JNFE7BMVF w $IBS4FRVFODF JT/VMM0S&NQUZ w $IBS4FRVFODF JT/VMM0S#MBOL w $PMMFDUJPO JT/VMM0S&NQUZ w .BQ JT/VMM0S&NQUZ w "SSBZ JT/VMM0S&NQUZ Ͱ͸໿ϝιουʹରԠ
  7. w 3FTVMUHFU0S&MTF w 3FTVMUGPME w 3FTVMUNBQ w 3FTVMUSFDPWFS w 3FTVMUPO'BJMVSF

    w 3FTVMUPO4VDDFTT w SFRVJSF w SFRVJSF/PU/VMM w DIFDL w DIFDL/PU/VMM w FSSPS 4UEMJCͰͷར༻ঢ়گ w SVO w XJUI w BQQMZ w BMTP w MFU w UBLF*G w UBLF6OMFTT w SFQFBU w NFBTVSF5JNF w NFBTVSF5JNFE7BMVF w $IBS4FRVFODF JT/VMM0S&NQUZ w $IBS4FRVFODF JT/VMM0S#MBOL w $PMMFDUJPO JT/VMM0S&NQUZ w .BQ JT/VMM0S&NQUZ w "SSBZ JT/VMM0S&NQUZ Ͱ͸໿ϝιουʹରԠ
  8. w ೚ҙͷߏจΛ࣮૷͢Δ͜ͱ͕Մೳ w ੍໿͕๛෋ͰOVMM OVMM USVF GBMTF @ ೚ҙ GBJMͳͲ͕͋Δ

    w Ҿ਺͸ෳ਺ࢦఆͰ͖Δ w "#zܗࣜɻ"Λϝιουʹఏڙ͢Δͱ#ΛಘΔͱ͍͏ҙ ຯͰͷܖ໿Λܗ੒ w γϯϘϧΛར༻͢Δ͜ͱͰɺҾ਺ͱ໭Γ஋ͷؒͷҼՌؔ܎ Λࣔ͢ !$POUSBDUϝϦοτ
  9. جຊߏจ 'VODUJPO $POUSBDU &GGFDU &GGFDU &GGFDU w &GGFDU w $BMMT*O1MBDF

    w DBMMT*O1MBDF w $POEJUJPOBM&GGFDU w JNQMJFT w 4JNQMF&GGFDU w 3FUVSOT w SFUVSOT w 3FUVSOT/PU/VMM w SFUVSOT/PU/VMM
  10. w &YQFSJNFOUBMͳػೳ w มߋ͕͋Δ͔΋͠Εͳ͍ w ࣍ͷόʔδϣϯͰ͋ΔΛλʔήοτͨ͠*TTVF͕ଟ਺͋Δ w IUUQTZPVUSBDLKFUCSBJOTDPNJTTVF,5 w IUUQTZPVUSBDLKFUCSBJOTDPNJTTVF,5

    w IUUQTZPVUSBDLKFUCSBJOTDPNJTTVF,5 w Ͱ%FQSFDBUFEʹͳΔ͜ͱ͸ͳͦ͞͏ʂ w ,PUMJO$POGͰʹ͍ͭͯͷൃද͕͋ΔͷͰظ଴ʂ ࠓޙͷల։