R3 compatible MAP
; R3-compatible interface
map: func ['word data [block!] body [block!]] [
collect/only res compose/deep [
repeat (word) data [res: do bind/copy body (to lit-word! word)]
]
]
11380 users tagging and storing useful source code snippets
Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
; R3-compatible interface
map: func ['word data [block!] body [block!]] [
collect/only res compose/deep [
repeat (word) data [res: do bind/copy body (to lit-word! word)]
]
]
def serial_task(name, options = {}, &block) servers = self.roles[options[:roles]].collect {|server| server.host} task_syms = [] servers.each do |hostname| role_sym = "_serial_task_#{name.to_s}_#{hostname}".to_sym task_sym = "_do_task_#{name.to_s}_#{hostname}".to_sym task_syms << task_sym role role_sym, hostname task task_sym, :roles => role_sym, &block end task name do task_syms.each do |t| self.send t end end end
serial_task :pwd, :roles => web do run "pwd" end
merge: func [ "Merge A and B together, like a zipper, alternating elements" a [series!] b [series!] /only "Merge items as sub-blocks" /local res val ][ res: make a length? a repeat i max length? a length? b [ val: reduce [pick a i pick b i] either only [append/only res val] [append res val] ] res ]
limit: func [
"Make sure val falls between lower and upper bounds, inclusive; uses length for series values."
val
lower [integer!]
upper [integer!]
/show "For series values, show extension/truncation (dot/none for extension, 3 dots for truncation)."
/local fill
][
either not series? val [max min val upper lower] [
either all [
upper >= length? val
lower <= length? val
] [val] [
; If extending the series, use NONE as the fill value, so the
; block can still be processed easily.
fill: either any-string? val ["."] [none]
head either lower >= length? val [
insert/only/dup tail val fill subtract lower length? val
][
clear skip val upper
either show [change/dup skip tail val -3 '. 3] [val]
]
]
]
]
sparse-rec-to-fixed-block: func [ rec [block!] col-names [block!] "All column names in full schema" ][ if not all-words? col-names [alert join "sparse-rec-to-fixed-block: col-names has non-word values: " mold col-names] collect/only val [ foreach name col-names [ val: attempt [first select/skip rec name 2] ] ] ]
; Like named-fields?, this func can't guarantee that a record is really ; a sparse rec; it can only tell us if it's not. sparse-rec?: func [ rec [block!] col-names [block!] "All column names in full schema" ][ if not all-words? col-names [alert join "sparse-rec?: col-names has non-word values: " mold col-names] all [ named-fields? rec (length? rec) <> (2 * length? col-names) ] ]
sort-by-length: func [series] [sort/compare series :cmp-length]
; Support func for stable sort comparator
cmp-length: func [a [series!] b [series!] /local len-a len-b] [
len-a: length? a
len-b: length? b
case [
len-a < len-b [-1]
len-a > len-b [1]
len-a = len-b [0]
]
]
drop-highest: func [block] [head remove maximum-of block]
drop-lowest: func [block] [head remove minimum-of block]