Re: [Pharo-users] Maybe Monad

2018-01-26 Thread Ben Coman
On 27 January 2018 at 08:33, horrido  wrote:
> Is there a Pharo equivalent to Ruby's Maybe monad? See
> https://github.com/rap1ds/ruby-possibly

>From that page I read...
   "Maybe monad is a programming pattern that allows to treat nil
values that same way as non-nil values"

At a minimum you can just define required methods on UndefinedObject.
For example...
UndefinedObject >> myThing
   self inform: 'Nil does my thing!!'

then in Playground evaluate...
nil myThing

This obviously doesn't cover the "Some" part of Maybe-monad,
but you didn't provide any description of what you're trying to do so
I don't know how important that is to you.

However, in general a better approach than adding methods to
UndefinedObject if to use the Null pattern.
Initialize your variables with an instance of MyDomainNull which
defines the minimum required messages to avoid DNUs.
Such a class might fit as the root superclass of all your domain classes.
But this suggestion might be off target, since I can't grok where I'd
use something like Maybe-Monad in my own programming.

cheers -ben



[Pharo-users] Maybe Monad

2018-01-26 Thread horrido
Is there a Pharo equivalent to Ruby's Maybe monad? See
https://github.com/rap1ds/ruby-possibly




--
Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html



Re: [Pharo-users] looking for another iterator :)

2018-01-26 Thread Sean P. DeNigris
Evan Donahue wrote
> It is also worth mentioning that there is now also the Cons library
> available
> through the Pharo6 catalog browser… just creates an iterator and never
> actually creates the whole list…The code is stable and in use in several
> of my projects. 

Very interesting! Thanks :)



-
Cheers,
Sean
--
Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html



[Pharo-users] GSoC 2018: Old Topics Must Be Removed

2018-01-26 Thread Oleksandr Zaytsev
Hello!

I have noticed that some of the projects in Pharo GSOC 2018 Ideas List
 are copied from last year's list. I've asked
people who have been assigned as mentors to these projects and they told me
that they will not be mentoring them this year.

I have created a pull request
 for
removing two old projects that I found and discussed with mentors. But
there's probably more.

I think that the list of ideas has to be thoroughly reviewed and old
projects must be removed from it before students start applying for them.

Is there someone maintaining that list, who keeps track of all projects and
knows which ones to remove?

Oleks


Re: [Pharo-users] Lengthy operations block UI

2018-01-26 Thread Andrei Stebakov
Basically the test confirms that the long lasting scraping operation
returns the expected result . As you suggested let me take a look at Zn

On Jan 26, 2018 10:31, "Sven Van Caekenberghe"  wrote:

>
>
> > On 26 Jan 2018, at 16:16, Andrei Stebakov  wrote:
> >
> > How do you handle forked operations from TestCase point of view, when
> the test expects a value to assert from an asynchronous operation?
>
> tests typically run sequential & synchronous, it is hard to work with them
> otherwise (to debug them, to handle there failures).
>
> it is of course possible to write much more complex tests, doing all kind
> of magic, but well, they are complex and require experience.
>
> many Zn test run http client against http servers, you could look there
> for examples.
>
> what is your exact scenario or use case ?
>
> > On Jan 25, 2018 10:41, "Andrei Stebakov"  wrote:
> > Thanks, Sven, got it
> >
> > On Jan 25, 2018 10:36, "Sven Van Caekenberghe"  wrote:
> > Hi Andrei,
> >
> > > On 25 Jan 2018, at 16:26, Andrei Stebakov  wrote:
> > >
> > > I have written some code that has a deep nested loop of calling
> ZnClient>>get.
> > > In the loop I also execute Transcript>>show but I can only see the
> transcript output after a few seconds when the loop is finished. During all
> that time while the loop is busy the UI is also unresponsive.
> > > Is there a way to execute code in some sort of asynchronous way?
> >
> > The problem is not specific to using ZnClient, it is with every loop you
> execute in the UI thread: the Transcript output is not updated (as it is
> the UI thread itself that has to do the drawing).
> >
> > For example, try
> >
> >   1 to: 10 do: [ :i | Transcript crShow: i. 5 seconds wait ].
> >
> > The solution is to run you long running code in another thread, like this
> >
> >   [ 1 to: 10 do: [ :i | Transcript crShow: i. 5 seconds wait ] ] fork.
> >
> > HTH,
> >
> > Sven
>
>
>


Re: [Pharo-users] Lengthy operations block UI

2018-01-26 Thread Sven Van Caekenberghe


> On 26 Jan 2018, at 16:16, Andrei Stebakov  wrote:
> 
> How do you handle forked operations from TestCase point of view, when the 
> test expects a value to assert from an asynchronous operation?

tests typically run sequential & synchronous, it is hard to work with them 
otherwise (to debug them, to handle there failures).

it is of course possible to write much more complex tests, doing all kind of 
magic, but well, they are complex and require experience.

many Zn test run http client against http servers, you could look there for 
examples.

what is your exact scenario or use case ?

> On Jan 25, 2018 10:41, "Andrei Stebakov"  wrote:
> Thanks, Sven, got it
> 
> On Jan 25, 2018 10:36, "Sven Van Caekenberghe"  wrote:
> Hi Andrei,
> 
> > On 25 Jan 2018, at 16:26, Andrei Stebakov  wrote:
> >
> > I have written some code that has a deep nested loop of calling 
> > ZnClient>>get.
> > In the loop I also execute Transcript>>show but I can only see the 
> > transcript output after a few seconds when the loop is finished. During all 
> > that time while the loop is busy the UI is also unresponsive.
> > Is there a way to execute code in some sort of asynchronous way?
> 
> The problem is not specific to using ZnClient, it is with every loop you 
> execute in the UI thread: the Transcript output is not updated (as it is the 
> UI thread itself that has to do the drawing).
> 
> For example, try
> 
>   1 to: 10 do: [ :i | Transcript crShow: i. 5 seconds wait ].
> 
> The solution is to run you long running code in another thread, like this
> 
>   [ 1 to: 10 do: [ :i | Transcript crShow: i. 5 seconds wait ] ] fork.
> 
> HTH,
> 
> Sven




Re: [Pharo-users] Lengthy operations block UI

2018-01-26 Thread Andrei Stebakov
How do you handle forked operations from TestCase point of view, when the
test expects a value to assert from an asynchronous operation?

On Jan 25, 2018 10:41, "Andrei Stebakov"  wrote:

> Thanks, Sven, got it
>
> On Jan 25, 2018 10:36, "Sven Van Caekenberghe"  wrote:
>
>> Hi Andrei,
>>
>> > On 25 Jan 2018, at 16:26, Andrei Stebakov  wrote:
>> >
>> > I have written some code that has a deep nested loop of calling
>> ZnClient>>get.
>> > In the loop I also execute Transcript>>show but I can only see the
>> transcript output after a few seconds when the loop is finished. During all
>> that time while the loop is busy the UI is also unresponsive.
>> > Is there a way to execute code in some sort of asynchronous way?
>>
>> The problem is not specific to using ZnClient, it is with every loop you
>> execute in the UI thread: the Transcript output is not updated (as it is
>> the UI thread itself that has to do the drawing).
>>
>> For example, try
>>
>>   1 to: 10 do: [ :i | Transcript crShow: i. 5 seconds wait ].
>>
>> The solution is to run you long running code in another thread, like this
>>
>>   [ 1 to: 10 do: [ :i | Transcript crShow: i. 5 seconds wait ] ] fork.
>>
>> HTH,
>>
>> Sven
>>
>


Re: [Pharo-users] looking for another iterator :)

2018-01-26 Thread Steffen Märcker

Hi!

No stress is good news!


- what is the API in terms of vocabulary (ie drop the same as reject)


These are the operations implemented so far. |= means "satisfies", i.e.,  
evaluate to true.


Drop  drop first n elements
DropWhile drop first elements |= a block
Filter*   pick only elements |= a block
Keep* only use elements ~= nil
Map*  map each element
MapKeys*  map each element an use as key
Partition split after n elements
PartitionBy   split after elements |= a block
RandomSample* pick elements with probability p
Reductionsintermediate results of reduce
Remove*   = Filter not
Replace*  replace elements by LUT
Cat*  concatenate sequences
Deduperemove consecutive duplicates
Flatten*  flatten nested sequence
Take  pick first n elements
TakeNth   pick every n-th element
TakeWhile pick first elements |= a block
Tee   UNIX tee, concurrent evaluation

Note, * means that the operation is parallelizable. As the operations are  
independent of the sequence class, the apply naturally to all kinds of  
sources, like collections, streams, channels and so on.



- can we reexpress some of our iterators?


Most of them. For example, generic for all collections:

collect: aBlock
  ^self class <~ aBlock map <~ self
reject: aBlock
  ^self class <~ ablock remove <~ self
select: aBlock
  ^self class <~ aBlock filter <~ self

As said before, names are not fixed yet and there is a more classical API  
on top available, too:


collect: aBlock
  ^(self transduce map: aBlock) into: self class


- what is the cost?


Very little. In detail:
1) Upfront there is the constant cost of instantiating the tranducers.
2) The linear cost of evaluating a nested block for each element. This is  
likely to be optimized by the JIT, as the structure is very regular.


I only did some micro-benchmarks which showed little to none impact on  
performance so far.


Best,
Steffen