code-hex / synchro Goto Github PK
View Code? Open in Web Editor NEW🕰️ Synchro: Timezone-typesafe date and time framework for Go. 🌟 Star to support our work!
License: MIT License
🕰️ Synchro: Timezone-typesafe date and time framework for Go. 🌟 Star to support our work!
License: MIT License
golang/go#61897 がacceptedになりました。
これに伴い、コレクションを返すAPIではiter.Seq
を返すことがおそらく一般的になっていくと思います。
例えばGo標準ライブラリのproposal golang/go#53987 (comment) は、最終的にiter.Seq
を返すAPIとしてacceptされました。
同様に、synchroでコレクションを返すAPIをiter.Seq
に対応させるプランはあるでしょうか?(もしあれば、実装することに興味があります)
具体的には以下のようなものです。
細かいところが十分考えられていないのですが、少し見ていただいた印象としてもしポジティブであればより具体的に考えたいと思っています。
synchro
ではコレクションを返すメソッドとしてPeriod[T]
などがunexportedな型periodical[T]
を返しており、これの実体は<-chan Time[T]
になっていると思います。これの代わりに、iter.Seq
を返すようにするというProposalです。
func (Period[T]) Periodic() iter.Seq[Time[T]]
Edit: 最初aliasを使う形で書いていたのですが、言語仕様上できないことに気づき、修正しました。
iter.Seq
を前提としたAPIと組み合わせられるようになること実は具体的なユースケースが手元にあるわけではなく、これを提供することで大きいメリットがあるかどうかはわかっていません。
nobishino@1fd8814 でテストを書きましたが、少なくとも一部で後方互換性がありません。
periodical
型がchannelなので、channel型の変数に代入できるという性質(テストのProperty 1)があった。periodical
の型定義をiter.Seq
に置き換えると、この代入はできなくなる。periodical
型がchannelなので、for ~ range文で直接使うこともできた(テストのProperty 2)。この性質はrange over funcが実装された後のGoバージョンでは維持される。Slice
メソッドを削除する必要が生じる。
Slice
メソッドを定義できるようにtype periodical[T TimeZone] iter.Seq[Time[T]]
を戻り値とした場合、戻り値の値をiter.Seq[Time[T]]
型の変数(関数の引数も含む)にそのままでは代入できなくなる。(型変換をすればできると思われる)Currently ConvertTz
has the following signature:
func ConvertTz[T TimeZone, U TimeZone](from Time[T]) Time[U]
Users have to specify both T and U at every call site like ConvertTz[T, U](...)
. However, if we change it to
func ConvertTz[U TimeZone, T TimeZone](from Time[T]) Time[U] // note that U and T are swapped
Users can simply call with ConvertTz[U](...)
and let T
be inferred from input arguments, which improves the ergnomics.
Ensure that it returns the same result no matter how many times it's called.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.