2

rescript を使用して DB に書き込むことの副作用をシミュレートしようとしています。

を呼び出すときにデータを配列にプッシュしたいのですrepository.addJs.Array.pushを返しますがint、私は気にしません。この関数が副作用を引き起こすことをすぐに知らせるunit署名が表示されるように、強制的に戻りたいと思います。unit

コードは次のとおりです(およびここに遊び場があります):

module Person = {
  type entity = {
    firstName: string
  }
  
  type repository = {
    add: entity => unit,
    getAll: unit => array<entity>
  }

  
  let createRepository = (): repository => {
    let storage: array<entity> = []
    
    {
        add: entity => {
          Js.Array.push(entity, storage)  // This has type: int -> Somewhere wanted: unit
          ()         // how to force to return 'unit' there ?
       },
        getAll: () => storage
    }
  }
}
4

1 に答える 1