You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+30-1Lines changed: 30 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -21,7 +21,7 @@ Scala-gopher is open source (license is Apache2); binaries are available from th
21
21
Scala-gopher is a scala library, build on top of Akka and SIP-22 async, which provide an implementation of
22
22
CSP [Communicate Sequential Processes] primitives, known as 'Go-like channels.' Also, analogs of go/defer/recover control-flow constructions are provided.
23
23
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.
25
25
26
26
27
27
@@ -292,6 +292,35 @@ go {
292
292
}
293
293
~~~
294
294
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).
channel.awriteAll(2 to n) andThen (_ => quit success true)
308
+
channel
309
+
}
310
+
311
+
deffilter(in:Channel[Int]):Input[Int] =
312
+
{
313
+
valfiltered= makeChannel[Int]()
314
+
valsieve= 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.
0 commit comments