Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nil values #256

Closed
halturin opened this issue Sep 11, 2023 · 8 comments
Closed

nil values #256

halturin opened this issue Sep 11, 2023 · 8 comments

Comments

@halturin
Copy link

I couldn't find how to enable the generation of nil values for my [][]float32 type. Could you please help me with this?

@PumpkinSeed
Copy link

Hi @halturin,

Can you please provide a use-case or explanation for what you want to see? I just don't understand what is the result what you want to get from gofakeit.

@halturin
Copy link
Author

Thanks for your reply.

i'm just expecting to see kind of [][]float32{nil, []float32{...}, nil, nil} or something. Currently, it fills all the values of any slice.

@PumpkinSeed
Copy link

As far as I know this is the closest solution, but it's not generating nil values:

package main

import (
	"fmt"

	"github.com/brianvoe/gofakeit/v6"
)

func main() {
	v := [][]float32{nil, []float32{12}, nil}
	gofakeit.Slice(&v)
	fmt.Println(v)
        // Output: [[6.5598885e+37 2.9083515e+38 1.9996555e+38 7.870126e+37 3.2749926e+37 2.658292e+38 1.0501455e+38] [1.4212272e+38] [1.647583e+38 2.382803e+38 3.0777828e+38 1.395749e+38 1.610417e+38]]
}

I think this requires some modification on the Slice function.

@halturin
Copy link
Author

halturin commented Sep 17, 2023

Unfortunately, it doesn't work. Imagine a multidimensional slice, say [][][][][]float32.

It would be great if the Slice method could check the item type using CanAddr method

@PumpkinSeed
Copy link

@halturin I know it does not work, because I said: "I think this requires some modification on the Slice function."

This means that the Slice function does not support such a requirement, so someone needs to add this functionality. :)
Also probably it will be a new function, because of backward compatibility.

@brianvoe
Copy link
Owner

The problem with this is if i randomized a nil in an array of []float32 I would get the same issue from others wondering why im only partially filling out the array.

This is more of a user issue than anything. Sounds like you should make your own lookup function and output it the way you want.

@halturin
Copy link
Author

Thanks for the reply. As soon as a slice/map can be nil, it's weird not to have the ability to assign nil as a value. It would be great to have another method like gofakeit.SliceWithNil(...) to add the probability of nil values. Up to you.

@brianvoe
Copy link
Owner

Im good. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants