Handbook
Glossary
coalesce ( alist -- specification )
Factor handbook
»
The language
»
Collections
»
Interval maps
Prev:
<interval-map> ( specification -- map )
Vocabulary
interval-maps
Inputs
alist
an association list with integer keys
Outputs
specification
array of the format used by
<interval-map>
Word description
Finds ranges used in the given alist, coalescing them into a single range.
Definition
USING:
arrays
assocs
kernel
make
math
sequences
sorting
;
IN:
interval-maps
::
coalesce
( alist -- specification )
[
alist
sort-keys
unclip
swap
[
first2
dupd
]
dip
[|
oldkey oldval key val |
oldkey 1
+
key
=
oldval val
=
and
[
oldkey
2array
oldval
2array
,
key
]
unless
key val
]
assoc-each
[
2array
]
bi@
,
]
{
}
make
;