diff --git a/.all-contributorsrc b/.all-contributorsrc index 0ed1c67de7..1de8d7ac03 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -1558,6 +1558,15 @@ "contributions": [ "code" ] + }, + { + "login": "a-h", + "name": "Adrian Hesketh", + "avatar_url": "https://avatars.githubusercontent.com/u/1029947?v=4", + "profile": "http://adrianhesketh.com/", + "contributions": [ + "code" + ] } ], "repoType": "github", diff --git a/README.md b/README.md index 87a3a7a96f..b08b239b8c 100644 --- a/README.md +++ b/README.md @@ -61,199 +61,200 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d Abdallah Hodieb
Abdallah Hodieb

πŸ› Adam Ruka
Adam Ruka

πŸ› πŸ’» 🚧 πŸ‘€ Adrian Dimech
Adrian Dimech

πŸ’» + Adrian Hesketh
Adrian Hesketh

πŸ’» Alex Pulver
Alex Pulver

πŸ› - Andi Pabst
Andi Pabst

πŸ› + Andi Pabst
Andi Pabst

πŸ› Andrew Wason
Andrew Wason

πŸ› πŸ’» Andy Slezak
Andy Slezak

πŸ’» Ansgar Mertens
Ansgar Mertens

🚧 πŸ’» πŸ› Anshul Guleria
Anshul Guleria

πŸ€” Ari Palo
Ari Palo

πŸ€” Armaan Tobaccowalla
Armaan Tobaccowalla

πŸ› - BartΕ‚omiej Jurek
BartΕ‚omiej Jurek

πŸ› + BartΕ‚omiej Jurek
BartΕ‚omiej Jurek

πŸ› Ben Bridts
Ben Bridts

πŸ“– Ben Chaimberg
Ben Chaimberg

πŸ“– Ben Farr
Ben Farr

πŸ“– Ben Walters
Ben Walters

πŸ€” Benjamin Macher
Benjamin Macher

πŸ“– Benjamin Maizels
Benjamin Maizels

πŸ’» πŸ‘€ - Bervianto Leo Pratama
Bervianto Leo Pratama

🚧 + Bervianto Leo Pratama
Bervianto Leo Pratama

🚧 Bill Cauchois
Bill Cauchois

πŸ€” Brecht Verhoeve
Brecht Verhoeve

πŸ€” Breland Miley
Breland Miley

πŸ’» CaerusKaru
CaerusKaru

πŸ’» 🚧 Calvin Combs
Calvin Combs

πŸ’» πŸ‘€ Camilo BermΓΊdez
Camilo BermΓΊdez

πŸ› - Campion Fellin
Campion Fellin

πŸ’» + Campion Fellin
Campion Fellin

πŸ’» Carter Van Deuren
Carter Van Deuren

πŸ› Chris Garvis
Chris Garvis

πŸ“– Christian Moore
Christian Moore

πŸ› Christophe Vico
Christophe Vico

πŸ› Christopher Currie
Christopher Currie

πŸ’» πŸ€” Christopher Rybicki
Christopher Rybicki

πŸ“– πŸ› πŸ’» - CommanderRoot
CommanderRoot

πŸ’» + CommanderRoot
CommanderRoot

πŸ’» Cory Hall
Cory Hall

πŸ› Cristian MΔƒgheruΘ™an-Stanciu
Cristian Măgherușan-Stanciu

πŸ› CyrusNajmabadi
CyrusNajmabadi

πŸ› πŸ€” Damian Silbergleith
Damian Silbergleith

πŸ’» πŸ› Daniel Dinu
Daniel Dinu

πŸ› πŸ’» Daniel Schmidt
Daniel Schmidt

πŸ› πŸ’» - Daniel Schroeder
Daniel Schroeder

πŸ› πŸ’» πŸ“– πŸ€” 🚧 + Daniel Schroeder
Daniel Schroeder

πŸ› πŸ’» πŸ“– πŸ€” 🚧 Dave Slotnick
Dave Slotnick

πŸ› David Bell
David Bell

πŸ’» Donald Stufft
Donald Stufft

πŸ› πŸ’» πŸ€” πŸ‘€ Dongie Agnir
Dongie Agnir

πŸ’» πŸ‘€ Eduardo Rabelo
Eduardo Rabelo

πŸ“– Eduardo Sena S. Rosa
Eduardo Sena S. Rosa

πŸ› - Elad Ben-Israel
Elad Ben-Israel

πŸ› πŸ’» πŸ€” 🚧 πŸ‘€ πŸ“’ + Elad Ben-Israel
Elad Ben-Israel

πŸ› πŸ’» πŸ€” 🚧 πŸ‘€ πŸ“’ Eli Polonsky
Eli Polonsky

πŸ› πŸ’» πŸ€” 🚧 πŸ‘€ Eric Z. Beard
Eric Z. Beard

πŸ“† Erik Karlsson
Erik Karlsson

πŸ› Eugene Kozlov
Eugene Kozlov

πŸ’» Fabio Gentile
Fabio Gentile

πŸ› Florian Eitel
Florian Eitel

πŸ€” - Glib Shpychka
Glib Shpychka

πŸ› + Glib Shpychka
Glib Shpychka

πŸ› Graham Lea
Graham Lea

πŸ€” πŸ‘€ Greg Lucas
Greg Lucas

πŸ’» Hamza Assyad
Hamza Assyad

πŸ› πŸ’» πŸ€” πŸ‘€ Hari Pachuveetil
Hari Pachuveetil

πŸ“ πŸ“– Hsing-Hui Hsu
Hsing-Hui Hsu

πŸ’» πŸ“– πŸ€” πŸ‘€ Ikko Ashimine
Ikko Ashimine

πŸ“– - James
James

πŸ› πŸ’» + James
James

πŸ› πŸ’» James Kelley
James Kelley

πŸ› James Mead
James Mead

πŸ’» James Siri
James Siri

πŸ’» 🚧 Jason Del Ponte
Jason Del Ponte

πŸ€” πŸ‘€ Jason Fulghum
Jason Fulghum

πŸ€” πŸ“† πŸ‘€ Jeff Malins
Jeff Malins

πŸ’» - Jerry Kindall
Jerry Kindall

πŸ“– πŸ€” + Jerry Kindall
Jerry Kindall

πŸ“– πŸ€” Jimmy Gaussen
Jimmy Gaussen

πŸ€” Johannes Weber
Johannes Weber

πŸ“– John Pantzlaff
John Pantzlaff

πŸ’» Jon Steinich
Jon Steinich

πŸ› πŸ€” πŸ’» Joseph Lawson
Joseph Lawson

πŸ‘€ Joseph Martin
Joseph Martin

πŸ› - Junix
Junix

πŸ› + Junix
Junix

πŸ› Justin Frahm
Justin Frahm

πŸ› Justin Taylor
Justin Taylor

πŸ› Kaizen Conroy
Kaizen Conroy

πŸ’» πŸ› Kaizen Conroy
Kaizen Conroy

πŸ’» Kaushik Borra
Kaushik Borra

πŸ› Knut O. Hellan
Knut O. Hellan

πŸ› - Kyle Thomson
Kyle Thomson

πŸ’» πŸ‘€ + Kyle Thomson
Kyle Thomson

πŸ’» πŸ‘€ Leandro Padua
Leandro Padua

πŸ› Liang Zhou
Liang Zhou

πŸ› πŸ’» Madeline Kusters
Madeline Kusters

πŸ’» πŸ› Maja S Bratseth
Maja S Bratseth

πŸ› Marcos Diez
Marcos Diez

πŸ› Mark Nielsen
Mark Nielsen

πŸ’» - Matthew Bonig
Matthew Bonig

πŸ› πŸ“ + Matthew Bonig
Matthew Bonig

πŸ› πŸ“ Matthew Pirocchi
Matthew Pirocchi

πŸ’» πŸ€” πŸ‘€ Meng Xin Zhu
Meng Xin Zhu

πŸ› Michael Neil
Michael Neil

🚧 Mike Lane
Mike Lane

πŸ› Mitch Garnaat
Mitch Garnaat

πŸ› πŸ’» πŸ€” πŸ‘€ Mitchell Valine
Mitchell Valine

πŸ› πŸ’» πŸ€” 🚧 πŸ‘€ - Mohamad Soufan
Mohamad Soufan

πŸ“– + Mohamad Soufan
Mohamad Soufan

πŸ“– Mykola Mogylenko
Mykola Mogylenko

πŸ› Naumel
Naumel

πŸ‘€ Neta Nir
Neta Nir

πŸ’» πŸ€” 🚧 πŸ‘€ Nick Lynch
Nick Lynch

πŸ› πŸ’» 🚧 πŸ‘€ Niranjan Jayakar
Niranjan Jayakar

πŸ› πŸ’» πŸ€” 🚧 πŸ‘€ Noah Litov
Noah Litov

πŸ’» 🚧 πŸ‘€ - Otavio Macedo
Otavio Macedo

πŸ’» πŸ› + Otavio Macedo
Otavio Macedo

πŸ’» πŸ› PIDZ - Bart
PIDZ - Bart

πŸ€” Peter Woodworth
Peter Woodworth

🚧 Petr Kacer
Petr Kacer

πŸ› Petra Barus
Petra Barus

πŸ’» Philip Cali
Philip Cali

πŸ€” Quentin Loos
Quentin Loos

πŸ€” - Raphael
Raphael

πŸ› + Raphael
Raphael

πŸ› Richard H Boyd
Richard H Boyd

πŸ› Rico Huijbers
Rico Huijbers

πŸ› πŸ’» πŸ€” 🚧 πŸ‘€ Romain Marcadier
Romain Marcadier

πŸ› πŸ’» 🎨 πŸ€” 🚧 πŸ‘€ πŸ“ SADIK KUZU
SADIK KUZU

πŸ‘€ SK
SK

πŸ€” Sam Fink
Sam Fink

πŸ’» πŸ‘€ - Sam Goodwin
Sam Goodwin

πŸ‘€ + Sam Goodwin
Sam Goodwin

πŸ‘€ Sebastian Korfmann
Sebastian Korfmann

πŸ› πŸ’» πŸ€” Sepehr Laal
Sepehr Laal

πŸ› Shane Witbeck
Shane Witbeck

πŸ€” Shiv Lakshminarayan
Shiv Lakshminarayan

πŸ’» 🚧 πŸ‘€ Somaya
Somaya

πŸ’» πŸ€” 🚧 πŸ‘€ Stephen Kuenzli
Stephen Kuenzli

πŸ“– - Takahiro Sugiura
Takahiro Sugiura

πŸ“– + Takahiro Sugiura
Takahiro Sugiura

πŸ“– The Gitter Badger
The Gitter Badger

πŸ’» 🚧 Thomas Poignant
Thomas Poignant

πŸ› Thomas Steinbach
Thomas Steinbach

πŸ› Thorsten Hoeger
Thorsten Hoeger

πŸ’» Tim Wagner
Tim Wagner

πŸ› πŸ€” Tobias Lidskog
Tobias Lidskog

πŸ’» - Tom Bonner
Tom Bonner

πŸ› + Tom Bonner
Tom Bonner

πŸ› Ty Coghlan
Ty Coghlan

πŸ› Tyler van Hensbergen
Tyler van Hensbergen

πŸ€” Vlad Hrybok
Vlad Hrybok

πŸ› Vladimir Shchur
Vladimir Shchur

πŸ› Will Bender
Will Bender

πŸ› Yan Zhulanow
Yan Zhulanow

πŸ’» - Yigong Liu
Yigong Liu

πŸ› πŸ€” + Yigong Liu
Yigong Liu

πŸ› πŸ€” Zach Bienenfeld
Zach Bienenfeld

πŸ› ajnarang
ajnarang

πŸ€” aniljava
aniljava

πŸ’» arnogeurts-sqills
arnogeurts-sqills

πŸ› πŸ’» cn-cit
cn-cit

πŸ› deccy-mcc
deccy-mcc

πŸ› - dependabot-preview[bot]
dependabot-preview[bot]

πŸ› 🚧 + dependabot-preview[bot]
dependabot-preview[bot]

πŸ› 🚧 dependabot[bot]
dependabot[bot]

🚧 dheffx
dheffx

πŸ› gregswdl
gregswdl

πŸ› guyroberts21
guyroberts21

πŸ“– mattBrzezinski
mattBrzezinski

πŸ“– mergify
mergify

🚧 - mergify[bot]
mergify[bot]

🚧 + mergify[bot]
mergify[bot]

🚧 nathannaveen
nathannaveen

🚧 seiyashima42
seiyashima42

πŸ› πŸ’» πŸ“– sullis
sullis

πŸ’» diff --git a/packages/@jsii/go-runtime/jsii-runtime-go/helpers.go b/packages/@jsii/go-runtime/jsii-runtime-go/helpers.go index 8228f9a41d..54f7bc2fce 100644 --- a/packages/@jsii/go-runtime/jsii-runtime-go/helpers.go +++ b/packages/@jsii/go-runtime/jsii-runtime-go/helpers.go @@ -2,23 +2,45 @@ package jsii import "time" -// Bool obtains a pointer to the provided bool. -func Bool(v bool) *bool { return &v } +type basicType interface { + bool | string | float64 | time.Time +} -// Bools obtains a pointer to a slice of pointers to all the provided booleans. -func Bools(v ...bool) *[]*bool { - slice := make([]*bool, len(v)) +// Ptr returns a pointer to the provided value. +func Ptr[T basicType](v T) *T { + return &v +} + +// PtrSlice returns a pointer to a slice of pointers to all of the provided values. +func PtrSlice[T basicType](v ...T) *[]*T { + slice := make([]*T, len(v)) for i := 0; i < len(v); i++ { - slice[i] = Bool(v[i]) + slice[i] = Ptr(v[i]) } return &slice } -// Number obtains a pointer to the provided float64. -func Number(v float64) *float64 { return &v } +// Bool returns a pointer to the provided bool. +func Bool(v bool) *bool { return Ptr(v) } + +// Bools returns a pointer to a slice of pointers to all of the provided booleans. +func Bools(v ...bool) *[]*bool { + return PtrSlice(v...) +} + +type numberType interface { + ~float32 | ~float64 | + ~int | ~int8 | ~int16 | ~int32 | ~int64 | + ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr +} -// Numbers obtains a pointer to a slice of pointers to all the provided numbers. -func Numbers(v ...float64) *[]*float64 { +// Number returns a pointer to the provided float64. +func Number[T numberType](v T) *float64 { + return Ptr(float64(v)) +} + +// Numbers returns a pointer to a slice of pointers to all of the provided numbers. +func Numbers[T numberType](v ...T) *[]*float64 { slice := make([]*float64, len(v)) for i := 0; i < len(v); i++ { slice[i] = Number(v[i]) @@ -26,26 +48,18 @@ func Numbers(v ...float64) *[]*float64 { return &slice } -// String obtains a pointer to the provided string. -func String(v string) *string { return &v } +// String returns a pointer to the provided string. +func String(v string) *string { return Ptr(v) } -// Strings obtains a pointer to a slice of pointers to all the provided strings. +// Strings returns a pointer to a slice of pointers to all of the provided strings. func Strings(v ...string) *[]*string { - slice := make([]*string, len(v)) - for i := 0; i < len(v); i++ { - slice[i] = String(v[i]) - } - return &slice + return PtrSlice(v...) } -// Time obtains a pointer to the provided time.Time. -func Time(v time.Time) *time.Time { return &v } +// Time returns a pointer to the provided time.Time. +func Time(v time.Time) *time.Time { return Ptr(v) } -// Times obtains a pointer to a slice of pointers to all the provided time.Time. +// Times returns a pointer to a slice of pointers to all of the provided time.Time values. func Times(v ...time.Time) *[]*time.Time { - slice := make([]*time.Time, len(v)) - for i := 0; i < len(v); i++ { - slice[i] = Time(v[i]) - } - return &slice + return PtrSlice(v...) } diff --git a/packages/@jsii/go-runtime/jsii-runtime-go/helpers_test.go b/packages/@jsii/go-runtime/jsii-runtime-go/helpers_test.go index dd25ee3f9e..4287dbeda9 100644 --- a/packages/@jsii/go-runtime/jsii-runtime-go/helpers_test.go +++ b/packages/@jsii/go-runtime/jsii-runtime-go/helpers_test.go @@ -7,6 +7,26 @@ import ( "github.com/stretchr/testify/assert" ) +func TestV(t *testing.T) { + // Bool + assert.Equal(t, true, *Ptr(true)) + assert.Equal(t, false, *Ptr(false)) + // Bools + assert.Equal(t, []*bool{Bool(true), Bool(false), Bool(false), Bool(true)}, *PtrSlice(true, false, false, true)) + // Float64 is supported because it doesn't require conversion. + assert.Equal(t, 123.45, *Ptr(123.45)) + assert.Equal(t, float64(123.45), *Ptr(float64(123.45))) + // String + assert.Equal(t, "Hello", *String("Hello")) + // Strings + assert.Equal(t, []*string{String("Hello"), String("World")}, *Strings("Hello", "World")) + // Time + now := time.Now() + assert.Equal(t, now, *Time(now)) + // Times + assert.Equal(t, []*time.Time{Time(now)}, *Times(now)) +} + func TestBool(t *testing.T) { assert.Equal(t, true, *Bool(true)) assert.Equal(t, false, *Bool(false)) @@ -19,6 +39,21 @@ func TestBools(t *testing.T) { func TestNumber(t *testing.T) { assert.Equal(t, 123.45, *Number(123.45)) assert.Equal(t, 1337.0, *Number(1337)) + // Floats. + assert.Equal(t, float64(float32(123.45)), *Number(float32(123.45))) + assert.Equal(t, float64(123.45), *Number(float64(123.45))) + // Ints. + assert.Equal(t, float64(1337), *Number(int(1337))) + // Signed. + assert.Equal(t, float64(127), *Number(int8(127))) + assert.Equal(t, float64(1337), *Number(int16(1337))) + assert.Equal(t, float64(1337), *Number(int32(1337))) + assert.Equal(t, float64(1337), *Number(int64(1337))) + // Unsigned. + assert.Equal(t, float64(127), *Number(uint8(127))) + assert.Equal(t, float64(1337), *Number(uint16(1337))) + assert.Equal(t, float64(1337), *Number(uint32(1337))) + assert.Equal(t, float64(1337), *Number(uint64(1337))) } func TestNumbers(t *testing.T) {