Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I join/reduce a list of strings to a single string?

Tags:

nix

I want to convert this

builtins.readFile ../../dotfiles/vim/commands.vim + "\n" +
builtins.readFile ../../dotfiles/vim/keybindings.vim + "\n" +
builtins.readFile ../../dotfiles/vim/plugins.vim

into something more dynamic. This is what I've got so far. It evaluates to a list of strings.

map
  ( fileName: builtins.readFile ( ../../dotfiles/vim + "/${fileName}" )
  ( builtins.AttrNames ( builtins.readDir ../../dotfiles/vim ) )
like image 268
ahstro Avatar asked Nov 15 '25 11:11

ahstro


1 Answers

With lib.concatStrings.

# Generic:
lib.concatStrings [ "a" "b" "c" ] # Returns "abc"

# Specific:

lib.concatStrings (
  ( map
    ( fileName: builtins.readFile ( ../../dotfiles/vim + "/${fileName}" )
    ( builtins.AttrNames ( builtins.readDir ../../dotfiles/vim ) )
  );
like image 164
ahstro Avatar answered Nov 18 '25 19:11

ahstro



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!