Skip to content

Shift on sum types #18370

Discussion options

You must be logged in to vote

Solved by using type refinement

fn new_flash(mut values map[string]json.Any, value json.Any) {
	flashes_key := 'flashes'
	if existing_data := values[flashes_key] {
		if existing_data is []json.Any {
			values[flashes_key] = arrays.concat(existing_data, value)
		} else {
			mut data := []json.Any{}
			data << existing_data
			values[flashes_key] = arrays.concat(data, value)
		}
	} else {
		values[flashes_key] = value
	}
}

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by einar-hjortdal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
1 participant