smallex v0.2.3 MapList
Map list library.
Link to this section Summary
Functions
Find map
Zip columns list(first line) and list of rows list(after second lines)
get_dummies
Make extracted keys map without specified key
Outer join keys to map-list on same key-value pair from another
Get maps that do not match value of key
Inner join keys to map-list on same key-value pair from another
To CSV (Pickup keys from first line)
Link to this section Functions
Link to this function
find(map_list, match_map, match_key)
Find map
Examples
iex> MapList.find( [ %{ "a" => "key1", "b" => 12 }, %{ "a" => "key2", "b" => 22 } ], %{ "a" => "key1" }, "a" )
%{ "a" => "key1", "b" => 12 }
iex> MapList.find( [ %{ "a" => "key1", "b" => 12 }, %{ "a" => "key2", "b" => 22 } ], %{ "a" => "key2" }, "a" )
%{ "a" => "key2", "b" => 22 }
iex> MapList.find( [ %{ "a" => "key1", "b" => 12 }, %{ "a" => "key2", "b" => 22 } ], %{ "a" => "key3" }, "a" )
nil
Link to this function
first_columns_after_rows(columns_rows, with_atom \\ :no_atom)
Zip columns list(first line) and list of rows list(after second lines)
Examples
iex> MapList.first_columns_after_rows( [ [ "c1", "c2", "c3" ], [ "v1", 2, true ], [ "v2", 5, false ] ] )
[ %{ "c1" => "v1", "c2" => 2, "c3" => true }, %{ "c1" => "v2", "c2" => 5, "c3" => false } ]
iex> MapList.first_columns_after_rows( [ [ "c1", "c2", "c3" ], [ "v1", 2, true ], [ "v2", 5, false ] ], :atom )
[ %{ c1: "v1", c2: 2, c3: true }, %{ c1: "v2", c2: 5, c3: false } ]
Link to this function
get_dummies(map_list, columns)
get_dummies
Examples
iex> MapList.get_dummies( [ %{ "c1" => "v1", "c2" => 2, "c3" => true }, %{ "c1" => "v2", "c2" => 5, "c3" => false } ], [ "c1" ] )
[ %{ "c1" => 0, "c2" => 2, "c3" => true }, %{ "c1" => 1, "c2" => 5, "c3" => false } ]
iex> MapList.get_dummies( [ %{ "c1" => "v1", "c2" => 2, "c3" => true }, %{ "c1" => "v2", "c2" => 5, "c3" => false } ], [ "c1", "c2" ] )
[ %{ "c1" => 0, "c2" => 0, "c3" => true }, %{ "c1" => 1, "c2" => 1, "c3" => false } ]
Link to this function
imputer(map_list, columns, strategy \\ "mean")
imputer
Examples
iex> MapList.imputer( [ %{ "c1" => "v1", "c2" => 2 }, %{ "c1" => "v2", "c2" => 5 }, %{ "c1" => "v3", "c2" => "" } ], [ "c2" ] )
[ %{ "c1" => "v1", "c2" => 2 }, %{ "c1" => "v2", "c2" => 5 }, %{ "c1" => "v3", "c2" => 3.5 } ]
iex> MapList.imputer( [ %{ "c1" => "v1", "c2" => 2 }, %{ "c1" => "v2", "c2" => 5 }, %{ "c1" => "v3", "c2" => nil } ], [ "c2" ] )
[ %{ "c1" => "v1", "c2" => 2 }, %{ "c1" => "v2", "c2" => 5 }, %{ "c1" => "v3", "c2" => 3.5 } ]
Link to this function
make_extracted_keys_map_exclude_key(map_list, exclude_key, no_match_value)
Make extracted keys map without specified key
Examples
iex> MapList.make_extracted_keys_map_exclude_key( [ %{ "a" => "key1", "b" => 12, "c" => 13 }, %{ "a" => "key2", "b" => 22 } ], "a", "new_value" )
%{"b" => "new_value", "c" => "new_value"}
Link to this function
merge(base_map_list, add_map_list, match_key, no_match_value)
Outer join keys to map-list on same key-value pair from another
Examples
iex> MapList.merge( [ %{ "a" => "key1", "b" => 12 }, %{ "a" => "key2", "b" => 22 } ], [ %{ "a" => "key1", "c" => 13 }, %{ "a" => "key3", "c" => 23 } ], "a", "no_match" )
[ %{ "a" => "key1", "b" => 12, "c" => 13 }, %{ "a" => "key2", "b" => 22, "c" => "no_match" } ]
Link to this function
no_match_maps(base_map_list, match_map_list, match_key)
Get maps that do not match value of key
Examples
iex> MapList.no_match_maps( [ %{ "a" => "key1", "b" => 12 }, %{ "a" => "key2", "b" => 22 } ], [ %{ "a" => "key1", "c" => 13 }, %{ "a" => "key3", "c" => 22 } ], "a" )
[ %{ "a" => "key2", "b" => 22 } ]
iex> MapList.no_match_maps( [ %{ "a" => "key1", "b" => 12 }, %{ "a" => "key2", "b" => 22 } ], [ %{ "a" => "key3", "c" => 13 } ], "a" )
[ %{ "a" => "key1", "b" => 12 }, %{ "a" => "key2", "b" => 22 } ]
iex> MapList.no_match_maps( [ %{ "a" => "key1", "b" => 12 }, %{ "a" => "key2", "b" => 22 } ], [ %{ "a" => "key1", "c" => 13 }, %{ "a" => "key2", "c" => 22 } ], "a" )
[]
Link to this function
replace(base_map_list, add_map_list, match_key)
Inner join keys to map-list on same key-value pair from another
Examples
iex> MapList.replace( [ %{ "a" => "key1", "b" => 12 }, %{ "a" => "key2", "b" => 22 } ], [ %{ "a" => "key1", "c" => 13 }, %{ "a" => "key3", "c" => 23 } ], "a" )
[ %{ "a" => "key1", "b" => 12, "c" => 13 }, %{ "a" => "key2", "b" => 22 } ]
Link to this function
to_csv(map_list, option \\ :quote)
To CSV (Pickup keys from first line)
Examples (Comment out as doctest does not work)
# iex> MapList.to_csv( [ %{ "c1" => "v1", "c2" => 2, "c3" => true }, %{ "c1" => "v2", "c2" => 5, "c3" => false } ] )
# "c1, c2, c3
“v1”, “2”, “true” “v2”, “5”, “false” “