Skip to content
This repository has been archived by the owner on Jul 25, 2023. It is now read-only.
/ goscala Public archive

用 Go 1.18 的 generic 仿造 Scala 功能。

License

Notifications You must be signed in to change notification settings

kigichang/goscala

Repository files navigation

GoScala

Migrate to github.com/dairaga/gs

利用 Go 1.18 (2022 年推出) 的 Generic,實作 Scala Monoid 功能。目前還在開發、測試、實驗。 API 還會再修改。請不要用在開發與正式環境。

目前已完成:

  • Option
  • Either
  • Try
  • Slice

編譯環境

請參考: How to use type parameters for generic programming

我的環境: Mac OS Big Sur 11.5.2 / Go 1.17.1,安裝 Go 1.18 步驟如下:

  1. cd ~
  2. git clone https://go.googlesource.com/go goroot
  3. cd goroot
  4. git checkout dev.typeparams
  5. cd src
  6. ./all.bash

Compile 時,還是需要用到 -gcflags -G=3

心得

因為版本還在開發中,還是會發生一些我覺得很奇怪的問題。不過比 Go 1.17 與 Go2Go 好一些。

語法上與 Go2Go 有些出入。如

Go2Go:

type Numeric interface {
    type int, ...
}

在 Go 1.18 變成

type Numeric interface {
    int, ....
}

相關資料,請見 Type Parameters Proposal

About

用 Go 1.18 的 generic 仿造 Scala 功能。

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published