Comments (3)
Agreed, in principle.
- I'm not sure I see the value of
map_or_default
givenmap_or
, though. map
would also need to be added, as would the lazy versions of these combinators.- Are you aware of the rationale for
map_or
taking its final parameter as a function, rather than being fully eager?
from bool_ext.
These are basically copy pasted from the set that std has for Option
map_or_default
exists, (and can be useful, presumably for similar usecases asOption::None.map_or_default
)- I'm not sure what
map
by itself would do in this context, as it doesn't make much sense on a type that isn't a container - Given the suggestion to rename
map
tomap_or_else
,map_or
would producedefault
ifself == false
andf()
ifself == true
, this reflectsOption
where we basically have a family, whereor
means "use the given value if we'reNone
"or_else
means "compute the function if we'reNone
" and "map" means "compute a transformation if we'reSome
", given an assumption of mapping oftrue
toSome(())
andfalse
toNone
, that would mean thatmap_or
would want to compute a value ifself == true
(if it didn't, we'd just haveunwrap or
but with reversed arguments)
from bool_ext.
I like the transformations around map
(map
->map_or_else
+ map_or
and map_or_default
) and will implement these for v0.4.
Re: the unwrap
methods--it is not a goal to turn the bool
API into a mirror of Option
, so I think the existing expect
method (combined with the expectation that the user will negate the value if they wish to panic on true
instead of false
) should be sufficient. I also like that expect
doesn't carry the connotation of unwrapping, given that, as you point out, bool
is not a container.
Thanks again, I very much appreciate you sharing your thoughts on this API!
from bool_ext.
Related Issues (2)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bool_ext.