Comments (6)
Not so sure about that, we already have map
and flatMap
which you can use.
from php-option.
When you use map
and flatMap
you should think about returned value from passed callback. If it changes, your code breaks.
And there almost no situation, when you really want to have Option<Option<Type>>
.
And I can not extend PhpOption library for adding this method, as of Some and None classes are final.
One of alternative is use this:
Option::ensure($value)
->flatMap(Option::ensure(function($v) { /* You can safelly return Option here, or just a value */ }))
, but amout of parenthesis makes me cry :(
from php-option.
As alternative, we can improve map
method, adding this behaviour to it, but this is non-BC
from php-option.
Without breaking BC we can simply allow to return non-Option value from flatMap
method, and pass it to Option::fromValue
method if so.
from php-option.
I kinda like map and flatMap's clarity, however one gets the most benefit from this when we have a type system like Haskell's or Scala's. I can see why JS would choose to also implement then
in this way, since we don't have the help of a compiler (well, a typesystem and type-checker) to tell us when we've double wrapped options by mistake.
I'd certainly consider a PR to add then
, if it would be useful to you @State. :)
from php-option.
Closing due to no activity.
from php-option.
Related Issues (18)
- Collection based options HOT 2
- Autocomplete HOT 1
- Allow to pass non-Option value to orElse method HOT 5
- Syntax sugar for some often cases HOT 4
- Build targets: 5.3 fails (remove); nothing for 7.0+ HOT 1
- add .gitattributes file HOT 1
- Use SPDX license identifier
- Failed to clone http://github.com/schmittjoh/php-option via git, https and http protocols, aborting. HOT 1
- composer install or composer require fail to download HOT 1
- Allow `getOrCall` to accept arguments for the callable HOT 1
- Laravel upgrade to 5.8 version HOT 4
- [PHP 8.1] Deprecation notice because of incompatible return type HOT 1
- PHP 8.1: New #[ReturnTypeWillChange] attribute HOT 2
- Generic typing of `Option::fromValue` results in `Option<valueType|null>`
- Feature Request: Allow `OptOut` of singleton approach for `None` HOT 10
- let's update the phpoption package HOT 2
- [Composer\Downloader\TransportException] HOT 5
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 php-option.