Nim: to add non-destructive procedure `shuffled`

Created on 28 Oct 2019  路  7Comments  路  Source: nim-lang/Nim

Summary

I want to add a non-destructive function shuffled.

Description

Now, shuffle procedure is bang procedure.
But,please make shuffle procedure make nondestructive.

now, shuffle procedure's type is

proc shuffle*[T](x: var openArray[T]) =

please make shuffled procedure is

proc shuffled[T](x: seq[T]): seq[T] =
  result = x
  shuffle(result)

Alternatives

Additional Information

Feature Stdlib

Most helpful comment

non-mutating version should be called shuffled.

All 7 comments

non-mutating version should be called shuffled.

openArray[T] is not a concrete type and as such cannot be returned. You can write something for seq, though, like this

proc shuffled[T](x: seq[T]): seq[T] =
  result = x
  shuffle(result)

[...] bang procedure.

We don't use that terminology here.

Regarding your suggestion to make a breaking change. We can't do that, because we don't make breaking changes.

I understood,thank you.

Is it possible to add shuffled?

Yes shuffled would be ok, but please edit your issue that you now want shuffled. Then I still can't guarantee that it will be implemented/merged, but I personally think it would be ok.

@krux02
Thank you.
I edit my issue.
Next I will make PR.

The request is solved by outplace.
I close this issue.

Was this page helpful?
0 / 5 - 0 ratings