Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport Ref<T> to 3.28 #111

Merged
merged 5 commits into from
Jan 27, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: php
php:
- hhvm
- hhvm-3.28
matrix:
allow_failures:
- php: hhvm
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) {}
}