Skip to content

Commit ba52766

Browse files
committed
rename ERef to Reference for clarity, thanks @glyph
1 parent c9cbb75 commit ba52766

2 files changed

Lines changed: 38 additions & 34 deletions

File tree

effect/ref.py

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from ._sync import sync_performer
66

77

8-
class ERef(object):
8+
class Reference(object):
99
"""
1010
An effectful mutable variable, suitable for sharing between multiple
1111
logical threads of execution, that can be read and modified in a purely
@@ -19,44 +19,47 @@ def __init__(self, initial):
1919

2020
def read(self):
2121
"""Return an Effect that results in the current value."""
22-
return Effect(ReadERef(eref=self))
22+
return Effect(ReadReference(ref=self))
2323

2424
def modify(self, transformer):
2525
"""
2626
Return an Effect that updates the value with ``fn(old_value)``.
2727
"""
28-
return Effect(ModifyERef(eref=self, transformer=transformer))
28+
return Effect(ModifyReference(ref=self, transformer=transformer))
2929

3030

31-
@attributes(['eref'])
32-
class ReadERef(object):
33-
"""Intent that gets an ERef value."""
31+
@attributes(['ref'])
32+
class ReadReference(object):
33+
"""Intent that gets a Reference's current value."""
3434

3535

36-
@attributes(['eref', 'transformer'])
37-
class ModifyERef(object):
38-
"""Intent that modifies an ERef value in-place with a transformer func."""
36+
@attributes(['ref', 'transformer'])
37+
class ModifyReference(object):
38+
"""
39+
Intent that modifies a Reference value in-place with a transformer func.
40+
"""
3941

4042

4143
@sync_performer
42-
def perform_read_eref(dispatcher, intent):
43-
"""Performer for :obj:`ReadERef`."""
44-
return intent.eref._value
44+
def perform_read_reference(dispatcher, intent):
45+
"""Performer for :obj:`ReadReference`."""
46+
return intent.ref._value
4547

4648

4749
@sync_performer
48-
def perform_modify_eref(dispatcher, intent):
50+
def perform_modify_reference(dispatcher, intent):
4951
"""
50-
Performer for :obj:`ModifyERef`.
52+
Performer for :obj:`ModifyReference`.
5153
52-
Note that while :obj:`ModifyERef` is designed to allow strong consistency,
53-
this performer is _not_ threadsafe, in the sense that it's possible to
54-
overwrite unobserved values. This may change in the future.
54+
Note that while :obj:`ModifyReference` is designed to allow strong
55+
consistency, this performer is _not_ threadsafe, in the sense that it's
56+
possible to overwrite unobserved values. This may change in the future.
5557
"""
56-
new_value = intent.transformer(intent.eref._value)
57-
intent.eref._value = new_value
58+
new_value = intent.transformer(intent.ref._value)
59+
intent.ref._value = new_value
5860
return new_value
5961

6062

61-
eref_dispatcher = TypeDispatcher({ReadERef: perform_read_eref,
62-
ModifyERef: perform_modify_eref})
63+
reference_dispatcher = TypeDispatcher({
64+
ReadReference: perform_read_reference,
65+
ModifyReference: perform_modify_reference})

effect/test_ref.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,39 +3,40 @@
33
from ._base import Effect
44
from ._sync import sync_perform
55
from .ref import (
6-
ERef, ModifyERef, ReadERef,
7-
eref_dispatcher)
6+
Reference, ModifyReference, ReadReference,
7+
reference_dispatcher)
88

99

10-
class ERefTests(TestCase):
11-
"""Tests for :obj:`ERef`."""
10+
class ReferenceTests(TestCase):
11+
"""Tests for :obj:`Reference`."""
1212

1313
def test_read(self):
1414
"""``read`` returns an Effect that represents the current value."""
15-
ref = ERef('initial')
16-
self.assertEqual(ref.read(), Effect(ReadERef(eref=ref)))
15+
ref = Reference('initial')
16+
self.assertEqual(ref.read(), Effect(ReadReference(ref=ref)))
1717

1818
def test_modify(self):
1919
"""``modify`` returns an Effect that represents modification."""
20-
ref = ERef(0)
20+
ref = Reference(0)
2121
transformer = lambda x: x + 1
2222
eff = ref.modify(transformer)
2323
self.assertEqual(eff,
24-
Effect(ModifyERef(eref=ref, transformer=transformer)))
24+
Effect(ModifyReference(ref=ref,
25+
transformer=transformer)))
2526

2627
def test_perform_read(self):
2728
"""Performing the reading results in the current value."""
28-
ref = ERef('initial')
29-
result = sync_perform(eref_dispatcher, ref.read())
29+
ref = Reference('initial')
30+
result = sync_perform(reference_dispatcher, ref.read())
3031
self.assertEqual(result, 'initial')
3132

3233
def test_perform_modify(self):
3334
"""
3435
Performing the modification results in transforming the current value,
3536
and also returns the new value.
3637
"""
37-
ref = ERef(0)
38+
ref = Reference(0)
3839
transformer = lambda x: x + 1
39-
result = sync_perform(eref_dispatcher, ref.modify(transformer))
40+
result = sync_perform(reference_dispatcher, ref.modify(transformer))
4041
self.assertEqual(result, 1)
41-
self.assertEqual(sync_perform(eref_dispatcher, ref.read()), 1)
42+
self.assertEqual(sync_perform(reference_dispatcher, ref.read()), 1)

0 commit comments

Comments
 (0)