rfc:tagged_unions

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
rfc:tagged_unions [2023/01/18 18:40] crellrfc:tagged_unions [2024/07/16 14:12] (current) crell
Line 118: Line 118:
  
 (I really have had to do something like that before.)  Combined with pattern matching, this would allow for a very robust way to handle objects being special and having additional context. (I really have had to do something like that before.)  Combined with pattern matching, this would allow for a very robust way to handle objects being special and having additional context.
 +
 +=== MongoDB Driver ===
 +
 +The MongoDB team has reached out to us with another example of what they would like to be able to do in their driver.
 +
 +Their planned code is below, for reference.  For more details and an explanation of their intent, see [[https://gist.github.com/alcaeus/0ded70ba7dbb686057224bc830651f74#file-01-enums-php|this gist]].
 +
 +<code php>
 +enum ReadPreference
 +{
 +    case Primary;
 +    case Secondary(?array $tagSets = null, ?int $maxStalenessSeconds = null);
 +    case PrimaryPreferred(?array $tagSets = null, ?int $maxStalenessSeconds = null);
 +    case SecondaryPreferred(?array $tagSets = null, ?int $maxStalenessSeconds = null);
 +    case Nearest(?array $tagSets = null, ?int $maxStalenessSeconds = null);
 +    
 +    static function withTagSets(?array $tagSets = null): self {}
 +    static function withMaxStaleness(?int $maxStalenessSeconds = null): self {}
 +}
 +
 +enum ReadConcern
 +{
 +    case Available;
 +    case Linearizable;
 +    case Local;
 +    case Majority;
 +    case Snapshot(?Timestamp $atClusterTime = null);
 +}
 +
 +enum WriteConcern
 +{
 +    case Majority(?int $timeout = null);
 +    case Unacknowledged;
 +    case Acknowledged(int $servers = 1, ?int $timeout = null);
 +    
 +    static function withTimeout(?int $timeout = null): self {}
 +}
 +</code>
  
 ===== Backward Incompatible Changes ===== ===== Backward Incompatible Changes =====
rfc/tagged_unions.1674067257.txt.gz · Last modified: 2023/01/18 18:40 by crell