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

*.NonEmpty.Replicate #33

Open
cmorley191 opened this issue May 9, 2019 · 4 comments
Open

*.NonEmpty.Replicate #33

cmorley191 opened this issue May 9, 2019 · 4 comments

Comments

@cmorley191
Copy link

Please add the following function to the nonempty collection modules (not just List)

List.NonEmpty.replicate (count: PositiveInt) -> (value: 'a) -> NonEmptyList<'a>

@jimboreilly
Copy link

Isn't this just Seq.take : int -> seq<'T> -> seq<'T>

@ntwilson
Copy link
Owner

ntwilson commented May 21, 2019

Actually, I think it's

let List.NonEmpty.replicate (PositiveInt count) value = 
  List.NonEmpty.create value (List.replicate (count -1) value)

@jimboreilly
Copy link

Ok I was misunderstanding the method signature, I read it as a function to copy (misinterpreted "replicate") the first n values

@cmorley191
Copy link
Author

cmorley191 commented Jul 11, 2019

I was planning on adding a version of this method for the base modules as well, not just the NonEmpty modules. (the NonEmpty modules take a PositiveInt, so the base modules take a NaturalInt).

If I call it List.replicate, then any user opening SafetyFirst will have List.replicate shadowed by the function requiring a NaturalInt instead of an int. I imagine we don't want to break code just by opening SafetyFirst.

#44 has a similar situation where the type signature of groupBy should be changed by SafetyFirst, but we'd rather not override the function, and we want to reserve appending ' to the function name for functions that can fail (return Result).

The idea suggested over there was to use a different (but close enough in intellisense) name for the function. Do we want to continue with that? How about List.repeat? (edit: LazyList.repeat exists: infinite repetition. repeatN? repeatFinite?) List.reproduce?

We may want to consider if it would be annoying to have to guess whether the original or the "safe-signature" version is being used (e.g., "group" or "groupBy"?, "replicate" or "repeat"?, "init" or "initialize"?). I've gone through my keyboard and it looks like ' and _ are the only symbols we can stick on the end of an identifier.

cmorley191 added a commit to cmorley191/SafetyFirst that referenced this issue Jul 11, 2019
cmorley191 added a commit to cmorley191/SafetyFirst that referenced this issue Jul 11, 2019
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