Skip to content

Commit 9b7aadc

Browse files
committed
added Effected to description.
1 parent 73007cd commit 9b7aadc

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

README.md

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Scala-gopher is open source (license is Apache2); binaries are available from th
2121
Scala-gopher is a scala library, build on top of Akka and SIP-22 async, which provide an implementation of
2222
CSP [Communicate Sequential Processes] primitives, known as 'Go-like channels.' Also, analogs of go/defer/recover control-flow constructions are provided.
2323

24-
Note, which this is not an emulation of go language structures in Scala, but rather a reimplementation of key ideas in 'scala-like' manner.
24+
Note, which this is not an emulation of go language structures in Scala, but rather a reimplementation of the main ideas in 'scala-like' manner.
2525

2626

2727

@@ -292,6 +292,35 @@ go {
292292
}
293293
~~~
294294

295+
## Effected{Input,Output,Channel}
296+
297+
One useful programming pattern, often used in CSP-style programming: have a channel from wich we read (or to where we write) as a part of a state. In Go language, this is usually modelled as a mutable variable, changed inside the same select statement, where one is read/written.
298+
299+
In scala-gopher, we have the ability to use a technique of 'EffectedChannel', which can be seen as an entity, which holds channel, can be used in read/write and can be changed only via effect (operation, which accepts previous state and return next).
300+
301+
Let's look on example:
302+
303+
~~~ scala
304+
def generate(n:Int, quit:Promise[Boolean]):Channel[Int] =
305+
{
306+
val channel = makeChannel[Int]()
307+
channel.awriteAll(2 to n) andThen (_ => quit success true)
308+
channel
309+
}
310+
311+
def filter(in:Channel[Int]):Input[Int] =
312+
{
313+
val filtered = makeChannel[Int]()
314+
val sieve = makeEffectedInput(in)
315+
sieve.aforeach { prime =>
316+
sieve <<= (_.filter(_ % prime != 0))
317+
filtered <~ prime
318+
}
319+
filtered
320+
}
321+
~~~
322+
323+
Here in 'filter', we generate a set of prime numbers, and make a sieve of Eratosthenes by sequentially applying 'filter' effect to state of sieve EffectedInput.
295324

296325

297326
## Transputers

0 commit comments

Comments
 (0)