Repository navigation
Lower more of Elixir's stdlib on Rust's collections - #26
Merged
Merged
Conversation
length, map_size, and MapSet.size are len(), a usize where one is
expected, as is arithmetic on them there. Enum.empty?/1 and comparing with
[] or %{} are is_empty(). %{} and %{key => value} build a map where one is
expected. A generator over a map or set behind a reference iterates it by
reference, copying copy keys and values. first..last//step counts up
between dynamic bounds, and ++ concatenates lists.
…catenation A comprehension's type binds each generator in turn, Some and Ok patterns included, so a map it builds is typed; a tuple bound with = types each variable; a Vec read from Rust is a list. A map is indexed by a borrowed key. Collecting into a slice argument borrows a collected Vec. concat and zip take a list only at its last use. An iterator collected into a list and iterated again is iterated directly, and a generator over one value computes it before the item moves.
…e in use Enum.reduce builds its accumulator as the expected type and is typed by its reducer when its initial value is not. Indexing a map or list is typed, nested aliases resolve, and types rebuilt from Rust syntax keep their kinds. Values put into a list or pushed while still in use are copied, a value behind a reference is copied rather than updated in place, and list patterns bind items by reference.
… closures
Enum.sort sorts booleans, strings, and tuples. Map and set generators are
typed, specs of maps and sets keep their key and value types, and an
Elixir integer binding takes the integer type its uses need. %{} builds a
map where a reference to one is expected, unknown keys are borrowed, and
a closure only calling a function is that function.
…, propagate fallible concatenation, clone through double references
… literal membership, and iterate in-use tuple lists by reference
…rs, and keep the types bindings are given
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Gaps found while rewriting Figler's defrust code in plain Elixir style: comprehensions,
Enum.reduce,Map/MapSet, list patterns,[]/%{}, and interpolation instead of.iter(),HashMap::new(),deref, andref.Map.update/4, which matches the present value;List.replace_at/3;Enum.sort/1on ordered lists;MapSet.new/1of listed items (HashSet::from);String.downcase/1andString.upcase/1;x in [literals], which becomes an array check;[],%{},"", andnil, which becomeis_empty()andis_some()/is_none().++andMap.updategrow an owned list or map instead of cloning it. Afor … reduce:with one variable clause names its accumulator after that variable and annotates its type.and/or, andif;.as_ref().format!.for … reduce:becomesEnum.reduceover a comprehension.=.&[..], not&vec![..].%{}isHashMap::new().&strit already is.1..=n.into_iter(), which doesn't compile.mix cipasses (920 tests). With this branch, Figler regenerates clippy-clean (-D warnings), and its tests pass apart from the package test, which can't build a Hex package while dependencies are local paths.