The design suggestion Additional Option module functions has been marked "approved in principle".
This RFC covers the detailed proposal for this suggestion.
- Approved in principle
- Details: under discussion
- Implementation: Completed
Additional functions to Option
module
The approved names and forms are:
val defaultValue : 'a -> 'a option -> 'a
val defaultWith : (unit -> 'a) -> 'a option -> 'a
val orElse : 'a option -> 'a option -> 'a option
val orElseWith : (unit -> 'a option) -> 'a option -> 'a option
val map2: ('a -> 'b -> 'c) -> 'a option -> 'b option -> 'c option
val map3: ('a -> 'b -> 'c -> 'd) -> 'a option -> 'b option -> 'c option -> 'd option
val contains: 'a -> 'a option -> bool
val flatten: 'a option option -> 'a option
val apply: 'a option -> ('a -> 'b) option -> 'b option
We don't have any other functions in the F# core library working over containers of function values. Uses of this function are very rare and using it doesn't particularly make code more readable or even much more succinct. Any programmer who can use it correctly can write the one line helper.
These functions may be brought up at a later time. Action was not taken on these function definitions:
val ofTry : bool * 'a -> 'a option
Proposed names:
ofTry
ofByRef
Use case:
let parseInt x =
match System.Int32.TryParse x with
| false, _ -> None
| true, v -> Some v
becomes
let parseInt x =
System.Int32.TryParse x
|> Option.ofByRef
Provides a more complete relation to the Array
–List
–Seq
set,
as toArray
and toList
already exist.
val toSeq : 'a option -> 'a seq
inline
modifier: Should functions in theOption
module be marked as inline? If so, which ones would benefit the most?- study adopting
ExtCore.Option
module
The standard range of performance considerations for F# library functions apply.
The standard range of testing considerations for F# library functions apply.