mirror of
https://github.com/inkarkat/vim-ingo-library.git
synced 2026-05-29 11:18:51 +02:00
8035f7df8e
In particular, operations on Dict keys will turn List elements to Strings, but many clients expect to work with numbers, for example when working with tabpagebuflist(). Though the mapping is short and easy, it's been used in several places already, and having a small abstraction still is nice. As the optional str2nr() arguments complicate the invocation and are rarely used, let's define a special case for that.
33 lines
1004 B
VimL
33 lines
1004 B
VimL
" ingo/list/transform.vim: Functions to transform list elements.
|
|
"
|
|
" DEPENDENCIES:
|
|
"
|
|
" Copyright: (C) 2021 Ingo Karkat
|
|
" The VIM LICENSE applies to this script; see ':help copyright'.
|
|
"
|
|
" Maintainer: Ingo Karkat <ingo@karkat.de>
|
|
|
|
function! ingo#list#transform#str2nr( list, ... ) abort
|
|
"******************************************************************************
|
|
"* PURPOSE:
|
|
" Convert elements of a:list to numbers (replacing the original items).
|
|
"* ASSUMPTIONS / PRECONDITIONS:
|
|
" None.
|
|
"* EFFECTS / POSTCONDITIONS:
|
|
" None.
|
|
"* INPUTS:
|
|
" a:list Source list.
|
|
" a:base Optional conversion base.
|
|
" a:quoted Flag whether embedded single quotes are ignored.
|
|
"* RETURN VALUES:
|
|
" The modified a:list.
|
|
"******************************************************************************
|
|
if a:0 > 0
|
|
return map(a:list, 'call("str2nr", [v:val] + a:000)')
|
|
else
|
|
return map(a:list, 'str2nr(v:val)')
|
|
endif
|
|
endfunction
|
|
|
|
" vim: set ts=8 sts=4 sw=4 noexpandtab ff=unix fdm=syntax :
|