views:

81

answers:

1

I've noticed it seems to behave this way, but I don't want to rely on it if it's not intentional. Here's the code in question:

let bestValuesUnder max =
    allValues
    >> List.partition (fun value -> value < max)
    >> function
        | ([], bad) -> [List.min bad]
        | (good, _) -> good // |> List.sortBy (fun value -> -value)

allValues is a function that returns an int list.

+5  A: 

The spec does not say:

http://msdn.microsoft.com/en-us/library/ee353782(VS.100).aspx

but the current implementation in FSharp.Core does preserve order (it uses mutation under the hood to create the resulting lists in order, as it walks the original; this is efficient). I'll ask to see if we intend to promote this to the spec, as it seems like a useful guarantee.

Brian
Making good use of your RSS dashboard, I see :) Thanks for the input.
Cogwheel - Matthew Orlando
Yes, this is intended to be part of the spec, we'll update the docs.
Brian