Particularly the last two paragraphs. 

> Am 22.11.2016 um 17:32 schrieb Janis Voigtländer 
> <[email protected]>:
> 
> Have you seen what is written at the following location?
> 
> https://github.com/elm-lang/core/blob/master/CONTRIBUTING.md#adding-new-functions
> 
> 
>> Am 22.11.2016 um 17:21 schrieb Martin Cerny <[email protected]>:
>> 
>> Hi all,
>> I am currently about 3 side projects (small games) deep in Elm and the 
>> experience has been overally very good. I however encountered a few simple 
>> things I missed in the core libraries, so I would like to ask, if there is a 
>> reason to not have them there. If not, I'll be happy to file a pull request 
>> with them :-) 
>> 
>> So here they are, in order of decreasing importance (IMHO)
>> 
>> 1) List.get : Int -> List a -> Maybe a
>>  Just a way to get the nth element of a linked list in O(n) time. (the 
>> signature mimics that of Array.get). I know this exists in 
>> http://package.elm-lang.org/packages/circuithub/elm-list-extra/3.10.0/List-Extra
>>  but seems important enough to have it in the core.
>> 
>> 2) Random.constant : a -> Generator a
>> A generator that is not really a generator, but returns a fixed value. This 
>> is useful for composing generators with Random.map and Random.andThen or for 
>> the base case of recursive generators. An example use case is if I want to 
>> pick a value that is zero 50% percent of the time and 1-5 otherwise 
>> (happened in my game a few times)
>> This one is already present in 
>> http://package.elm-lang.org/packages/mgold/elm-random-pcg/latest/Random-Pcg 
>> which, according to https://github.com/elm-lang/core/issues/724 should 
>> replace the core Random in the future, but why not add it now :-)
>> 
>> generateValue : Bool -> Generator Float
>> generateValue isZero =
>>   if isZero then Random.constant 0 else Random.float 1 5
>> 
>> 
>> Random.bool |> Random.andThen generateValue
>> 
>> it also lets you write things like (which is probably not a very common use 
>> case, but came in handy for me):
>> 
>> listOfGeneratorsToGeneratorOfList : List (Random.Generator a) -> 
>> Random.Generator (List a)
>> listOfGeneratorsToGeneratorOfList listOfGenerators =
>>     case listOfGenerators of
>>         head :: tail ->
>>             Random.andThen
>>                 (listOfGeneratorsToGeneratorOfList tail)
>>                 (\list -> Random.map (\x -> x :: list) head)
>> 
>>         [] ->
>>             Random.constant []
>> 
>> currently, you can declare constant generator like this, but it seems stupid 
>> and wasteful:
>> 
>> constant : a -> Random.Generator a
>> constant value =
>>     Random.map (\_ -> value) Random.bool
>> 
>> 3) Random.permutation : List a -> Generator (List a)
>> This would simply pick a permutation of the original list at random. Might 
>> make sense to write this in javascript via converstion to array, as the O(n) 
>> algorithm (Knuth shuffle) for this does not seem to translate well into pure 
>> functional world...  I currently do not see a purely functional 
>> implementation that is not O(n^2), but I'll be happy to be proven wrong :-)
>> 
>> I understand that it is important to keep the core library slim (especially 
>> until dead code elimination is brought to Elm), so which of those you think 
>> should make the cut?
>> 
>> Looking forward to your ideas
>> Martin Černý
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Elm Discuss" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to [email protected].
>> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to