Skip to content

Commit

Permalink
Backport Ref<T> to 4.0 (#114)
Browse files Browse the repository at this point in the history
* Backport Ref<T> to 4.0

* Find the best hhvm that still passes travis

* Remove failing hhvm versions

Only hhvm 4.0 passes, since the others assume that `<?hh` means `// strict` instead of `// partial`
  • Loading branch information
lexidor authored and fredemmott committed Jan 21, 2020
1 parent 53806c8 commit f56140f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ sudo: required
language: generic
services: docker
env:
- HHVM_VERSION=latest
- HHVM_VERSION=4.0-latest

install:
- docker pull hhvm/hhvm:$HHVM_VERSION
script:
Expand Down
28 changes: 28 additions & 0 deletions src/Ref.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?hh // strict
/*
* Copyright (c) 2004-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/

namespace HH\Lib;

/** Wrapper class for getting object (byref) semantics for a value type.
*
* This is especially useful for mutating values outside of a lambda's scope.
*
* In general, it's preferable to refactor to use return values or `inout`
* parameters instead of using this class - however, a `Ref` of a Hack array
* is generally preferable to a Hack collection - e.g. prefer `Ref<vec<T>>`
* over `Vector<T>`.
*
* `C\reduce()` and `C\reduce_with_key()` can also be used in some situations
* to avoid this class.
*/
final class Ref<T> {
<<__RxShallow>>
public function __construct(public T $value) {}
}

0 comments on commit f56140f

Please sign in to comment.