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

入力を型で表現する

4239ea2bf38d7178476faa8787683105?s=47 Motoki Narita
October 25, 2017

 入力を型で表現する

4239ea2bf38d7178476faa8787683105?s=128

Motoki Narita

October 25, 2017
Tweet

Transcript

  1. ೖྗΛܕͰදݱ͢Δ !NPUPLJFF QPUBUPUJQT

  2. ࣗݾ঺հ w HJUIVC UXJUUFS!NPUPLJFF w ϝϧΧϦι΢κ΢J04ΤϯδχΞ w ϝϧΧϦΧ΢ϧνʔϜ w J04%$+BQBOελοϑ

  3. None
  4. ʙອըηοτͷग़඼ɾߪೖʹରԠ

  5. ग़඼ํ๏  όʔίʔυΛಡΈࠐΉ
 ˠ&"/ίʔυ͔Β"1*ܦ༝Ͱ੡඼৘ใΛऔಘ  λΠτϧ͔Βݕࡧ͢Δ
 ˠςΩετ͔Β੡඼৘ใΛऔಘʢ6*্ɺ੡඼σʔλ͸औಘࡁʣ

  6. %FNP

  7. ग़඼ը໘͸ͦͦ͜͜ෳࡶ w ܦ࿏͕ෳ਺ʢ͍·͸͚ͭͩͲʜʣ w όʔίʔυಡΈࠐΈ w λΠτϧݕࡧ w ϓϨʔεϗϧμͷදࣔ w

    ్தͰ੡඼ͷ৘ใ͕੾ΓସΘΔʢອըηοτʣ
  8. ෳ਺ͷೖྗΛͭͷܕͰදݱ

  9. struct ProactiveExhibit { enum Input: Equatable { case ean(String) case

    exhibit(BulkIncludeExhibit) } let input: Input } ೖྗͷந৅Խ
  10. struct ProactiveExhibit { enum Input: Equatable { case ean(String) case

    exhibit(BulkIncludeExhibit) } let input: Input } Χϝϥ͔ΒऔಘͰ͖Δ&"/ίʔυ
 ʢ੡඼৘ใऔಘΛ"1*ܦ༝Ͱऔಘʣ
  11. struct ProactiveExhibit { enum Input: Equatable { case ean(String) case

    exhibit(BulkIncludeExhibit) } let input: Input } λΠτϧݕࡧը໘͔Β౉͞ΕΔ੡඼৘ใ
 ʢݕࡧࡁΈͷ੡඼৘ใ͕ͦͷ··౉͞ΕΔʣ
  12. let input = Observable .of(scanCamera.barcodeNumber.map { ProactiveExhibit.Input.ean($0) }, exhibitAdapter.map {

    ProactiveExhibit.Input.exhibit(BulkIncludeExhibit(exhibits: [$0])) } ) .merge() .asDriver(onErrorDriveWith: .empty()) let removeExhibitsInput = Observable .merge(GlobalObservable.removeExhibitsForExhibitCamera, removeExhibitAdapter) .asDriver(onErrorDriveWith: .empty()) let replaceExhibitInput = replaceExhibitAdapter.asDriver(onErrorDriveWith: .empty()) viewModel = ExhibitCameraViewModel(input: input, removeExhibitsInput: removeExhibitsInput, replaceExhibitInput: replaceExhibitInput) Χϝϥ͔Β౉ͬͯ͘Δ&"/ίʔυͷετϦʔϜͱɺ
 λΠτϧը໘͔Β౉͞ΕΔ੡඼σʔλͷετϦʔϜΛNFSHF
 ˠ%SJWFS1SPBDUJWF&YIJCJU*OQVU
  13. let input = Observable .of(scanCamera.barcodeNumber.map { ProactiveExhibit.Input.ean($0) }, exhibitAdapter.map {

    ProactiveExhibit.Input.exhibit(BulkIncludeExhibit(exhibits: [$0])) } ) .merge() .asDriver(onErrorDriveWith: .empty()) let removeExhibitsInput = Observable .merge(GlobalObservable.removeExhibitsForExhibitCamera, removeExhibitAdapter) .asDriver(onErrorDriveWith: .empty()) let replaceExhibitInput = replaceExhibitAdapter.asDriver(onErrorDriveWith: .empty()) viewModel = ExhibitCameraViewModel(input: input, removeExhibitsInput: removeExhibitsInput, replaceExhibitInput: replaceExhibitInput) Χϝϥ͔Β౉ͬͯ͘Δ&"/ίʔυͷετϦʔϜ
  14. let input = Observable .of(scanCamera.barcodeNumber.map { ProactiveExhibit.Input.ean($0) }, exhibitAdapter.map {

    ProactiveExhibit.Input.exhibit(BulkIncludeExhibit(exhibits: [$0])) } ) .merge() .asDriver(onErrorDriveWith: .empty()) let removeExhibitsInput = Observable .merge(GlobalObservable.removeExhibitsForExhibitCamera, removeExhibitAdapter) .asDriver(onErrorDriveWith: .empty()) let replaceExhibitInput = replaceExhibitAdapter.asDriver(onErrorDriveWith: .empty()) viewModel = ExhibitCameraViewModel(input: input, removeExhibitsInput: removeExhibitsInput, replaceExhibitInput: replaceExhibitInput) λΠτϧը໘͔Β౉͞ΕΔ੡඼σʔλͷετϦʔϜ
  15. let input = Observable .of(scanCamera.barcodeNumber.map { ProactiveExhibit.Input.ean($0) }, exhibitAdapter.map {

    ProactiveExhibit.Input.exhibit(BulkIncludeExhibit(exhibits: [$0])) } ) .merge() .asDriver(onErrorDriveWith: .empty()) let removeExhibitsInput = Observable .merge(GlobalObservable.removeExhibitsForExhibitCamera, removeExhibitAdapter) .asDriver(onErrorDriveWith: .empty()) let replaceExhibitInput = replaceExhibitAdapter.asDriver(onErrorDriveWith: .empty()) viewModel = ExhibitCameraViewModel(input: input, removeExhibitsInput: removeExhibitsInput, replaceExhibitInput: replaceExhibitInput) ೖྗΛ7JFX.PEFMͷॳظԽ࣌ʹ౉͢
  16. 1SPBDUJWF&YIJCJU*OQVUͰ දࣔॲཧ΍"1*ϦΫΤετॲཧΛ෼͚Δ

  17. let fetchProgress = filteredInput .flatMap { [weak self] input ->

    Driver<Progress<(ProactiveExhibit.Input, [Exhibit])>> in switch input { case .ean(let ean): let request = ExhibitAPI.FindByEAN(ean: ean) let response = APIClient.shared.response(request) .map { response -> (ProactiveExhibit.Input, [Exhibit]) in return (input, response.elements) } return Progress.makeDriver(response) case .exhibit(let exhibit): return Driver.empty() } } *OQVUFBOͷ৔߹ͷΈϦΫΤετ
  18. class ExhibitScannedDisplayViewCell: UICollectionViewCell { // লུ var proactiveExhibit: ProactiveExhibit? {

    didSet { if let bulkIncludeExhibit = proactiveExhibit?.bulkIncludeExhibit { // ੡඼৘ใදࣔ } else { // ϓϨʔεϗϧμදࣔ } } } } "1*ϦΫΤετ͕ඞཁͳ৔߹ʢFBOʣ͸
 ϓϨʔεϗϧμΛදࣔ͢ΔΑ͏$FMMͰදࣔॲཧ
  19. class ExhibitScannedDisplayViewCell: UICollectionViewCell { // লུ var proactiveExhibit: ProactiveExhibit? {

    didSet { if let bulkIncludeExhibit = proactiveExhibit?.bulkIncludeExhibit { // ੡඼৘ใදࣔ } else { // ϓϨʔεϗϧμදࣔ } } } } ೖྗʹܕΛఆٛ͢Δ͜ͱͰσʔλͦͷ΋ͷͱ͸
 ผͰॲཧ͕Ͱ͖ΔΑ͏ʹͳΔ
  20. ෳ਺ͷೖྗΛͭͷܕͰදݱ w σʔλ͚ͩͰͳ͘ೖྗʹ΋ܕΛ w σʔλࣗମͷॲཧͱը໘ͷॲཧΛ෼཭͠΍͍͢ w ೖྗ಺༰ʹΑͬͯॲཧ͕ҟͳΔΑ͏ͳ৔߹ʹ༗ޮ w ࠓޙɺೖྗͷόϦΤʔγϣϯ͕૿͑ΔΑ͏ͳ͜ͱ͕͋ͬ ͯ΋ಉ͡ܕͰදݱ͢Δ͜ͱ͕Ͱ͖Δ

    w όϦΤʔγϣϯ͕૿͑ͨࡍ΋ίϯύΠϧΤϥʔ͕ग़Δͷ ͰɺҰͭҰͭରԠ͍͚ͯ͠͹ྑ͍
  21. ͓ΘΓ