Is there an F# equivalent of Enumerable.DefaultIfEmpty?

f#, linq

Solution

`Seq` module functions operate and return `IEnumerable<_>`'s and `DefaultIfEmpty` operate and return `IEnumerable<_>`'s. How about just wrap it in function that is composable.

let inline DefaultIfEmpty d l = System.Linq.Enumerable.DefaultIfEmpty(l, d)

This also preserves laziness.

example:

Seq.empty |> DefaultIfEmpty 0

Update

I've made an open source library inlining many extension and static methods, including `Enumerable.defaultIfEmpty` -- ComposableExtesions

Problem

After searching quite a bit, I couldn't find an F# equivalent of Enumerable.DefaultIfEmpty. Does something similar exists in F# (perhaps in a different, idiomatic, way)?

Original source