dbrattli / Expression

Pragmatic functional programming for Python inspired by F#
https://expression.readthedocs.io
MIT License
424 stars 31 forks source link

Add or_else_with #27

Closed 6293 closed 3 years ago

6293 commented 3 years ago

Some(42).or_else(f()) evaluates f() even though the result is never applied, and this is what you do not like when f() performs heavy computations. Some(42).or_else_with(lambda: f()) is the solution to this problem.

https://fsharp.github.io/fsharp-core-docs/reference/fsharp-core-optionmodule.html#orElseWith

codecov[bot] commented 3 years ago

Codecov Report

Merging #27 (1e8add4) into main (a9e41f2) will decrease coverage by 0.04%. The diff coverage is 60.00%.

@@            Coverage Diff             @@
##             main      #27      +/-   ##
==========================================
- Coverage   80.53%   80.48%   -0.05%     
==========================================
  Files          38       38              
  Lines        2173     2178       +5     
==========================================
+ Hits         1750     1753       +3     
- Misses        423      425       +2     
Impacted Files Coverage Δ
expression/core/option.py 87.83% <60.00%> (-0.76%) :arrow_down: