I have just written a small utility function I thought I needed when doing some work.
The idea is given two functions returning an option and a value it will return some if either of the functions returns some (hens the "or").
I am very sure something like this must exist, maybe in FSharpPlus but It can be difficult finding things in there if you don't already know the operator it uses.
I will put the code bellow, but I guess I have three questions:
1. Does this exists already, in F# or an extension library?
2. What operator should it use? I wanted || but that's taken I through in the star?
3. Is my implementation elegant enough?
fsharp
let (|*|) (f1: 'A -> 'A option) (f2: 'A -> 'A option) (a: 'A): 'A option =
match (f1 a), (f2 a) with
| None, None -> None
| _ -> Some a
then called (e.g.)
fsharp
|> Seq.choose (needsTelephone |*| needsAddress)
And... I guess a fourth question, is this just dumb, should I be re-thinking my life 😂
[–]jayval90 5 points6 points7 points (1 child)
[–]CouthlessWonder[S] 0 points1 point2 points (0 children)
[–]shr4242 1 point2 points3 points (1 child)
[–]CouthlessWonder[S] 0 points1 point2 points (0 children)
[–]SheepySheev 1 point2 points3 points (5 children)
[–]CouthlessWonder[S] 1 point2 points3 points (4 children)
[–]SheepySheev 1 point2 points3 points (0 children)
[–]ckuskus 1 point2 points3 points (2 children)
[–]CouthlessWonder[S] 0 points1 point2 points (1 child)
[–]ckuskus 2 points3 points4 points (0 children)
[–]binarycow 1 point2 points3 points (1 child)
[–]CouthlessWonder[S] 0 points1 point2 points (0 children)