Thank you Sven! This is really convenient.

SortFunctions are really cool.

Esteban A. Maringolo

On Tue, Jun 30, 2020 at 6:06 PM Sven Van Caekenberghe <s...@stfx.eu> wrote:
>
> Hi Stef,
>
> With the following commit 
> https://github.com/svenvc/ston/commit/3565d388172b76c180454575d4c2f71019f130c4
>
> there is now basic support for SortCollections using SortFunctions.
>
> All of the following can now be serialised and materialised by STON (see 
> #testSortedCollections):
>
> SortedCollection new.
> SortedCollection new: 0.
>
> #(5 3 7 2 1 4 10 9 8 6) asSortedCollection.
>
> #(5 3 7 2 1 4 10 9 8 6) asSortedCollection: #yourself ascending.
> #(5 3 7 2 1 4 10 9 8 6) asSortedCollection: #yourself descending.
>
> #('****' '*' '*****' '**' '***') asSortedCollection: #size ascending.
> #('****' '*' '*****' '**' '***') asSortedCollection: #size descending.
>
> #(5 3 7 2 1 4 10 nil 9 8 6) asSortedCollection: #yourself ascending 
> undefinedFirst.
> #(5 3 7 2 1 4 10 nil 9 8 6) asSortedCollection: #yourself ascending reversed 
> undefinedLast.
>
> I think this trick covers a large set of SortedCollection use cases avoiding 
> blocks by using SortFunctions.
>
> This technique could also be used to replace other block usages elsewhere.
>
> To answer your original question: yes we could add this to the documentation 
> (although right now it is very new and unproven).
>
> Regards,
>
> Sven
>
> > On 28 Jun 2020, at 12:25, Stéphane Ducasse <stephane.duca...@inria.fr> 
> > wrote:
> >
> >
> >
> >> On 27 Jun 2020, at 16:58, Sven Van Caekenberghe <s...@stfx.eu> wrote:
> >>
> >> Hi Russ,
> >>
> >> The limitation of STON not being capable of serialising a block closure 
> >> still stands and will probably not change very soon (it open up the whole 
> >> language to be written out).
> >>
> >> You can work around this though, with sort functions for example.
> >>
> >> Here is an example:
> >>
> >> { 1->#one. 3->#three. 2->#two } sorted: (STON fromString: (STON 
> >> toStringPretty: #key ascending)).
> >>
> >> SortFunctions are really cool BTW (they can handles nil values elegantly).
> >>
> >> Sven
> >
> > Sven do you think that we should have a little section on this question in 
> > STON chapter.
> >
> > S
>
>

Reply via email to