From 01be02f4cc9e341353e34082edc5659cf35ebf16 Mon Sep 17 00:00:00 2001 From: NaiJi Date: Wed, 27 Apr 2022 05:54:34 +0000 Subject: [PATCH] Add '31.nix' --- 31.nix | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 31.nix diff --git a/31.nix b/31.nix new file mode 100644 index 0000000..fdc4aa0 --- /dev/null +++ b/31.nix @@ -0,0 +1,15 @@ +with import { }; +let + attrSet = {c = 3; a = 1; b = 2;}; + #This is an example function that extracts a single value + getSingleVal = (attrSet: x: attrSet.${x}); + + #tips: use the map function and access the attribute values + #in the same way as 'getSingleVal' + attrVals = l: s: map (field: s.${field}) l; + +in +rec { + example = getSingleVal attrSet "a"; #is [1] + solution = attrVals ["a" "b" "c"] attrSet; #should be [1 2 3] +} \ No newline at end of file