-
Notifications
You must be signed in to change notification settings - Fork 28
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
Array.fromOneItem #109
base: main
Are you sure you want to change the base?
Array.fromOneItem #109
Conversation
What about calling it A bit on the fence on the general usefulness of this. Do you have some concrete real world examples to share? |
Good question. The designers of F# included an This is useful in pipeline mode where you end up with a single value and want to turn it into an array for further processing. I think It flows more nicely using
Years ago I programmed the board game Hive in F# and found this snippet. It is a function that returns a list of legal moves. In most cases the function naturally calculates a list of possibilities. But there are a couple cases where I know the result will just be a single possible move and so these become singletons.
I found this in I searched Github. This is a popular project. They use the https://github.com/lefthandedgoat/canopy/search?q=singleton Honestly I couldn't find many F# projects using this. It definitely is not essential - you can always work around it by wrapping that single value in |
Why not just call it In |
I think it depends on whether we want to have a standard of using
|
Personally I agree. But since the primary guiding principle is familiarity for JS developers I would expect direct bindings to JS functions to be named the same as their counterpart. |
You can always have both an |
|
eca459b
to
363fb9e
Compare
Creates an array from a single value. Includes documentation and tests. Zero cost binding to
Array.of
. F# has this by the nameArray.singleton
. Useful in pipeline mode to convert a single value into an array. Other possible namesfromOne
,fromOneValue
,fromSingleItem
,fromSingleValue
,fromSingleton
.