immutable-ruby 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/immutable.rb +9 -0
- data/lib/immutable/core_ext.rb +2 -0
- data/lib/immutable/core_ext/enumerable.rb +11 -0
- data/lib/immutable/core_ext/io.rb +21 -0
- data/lib/immutable/deque.rb +254 -0
- data/lib/immutable/enumerable.rb +152 -0
- data/lib/immutable/hash.rb +841 -0
- data/lib/immutable/list.rb +1595 -0
- data/lib/immutable/nested.rb +75 -0
- data/lib/immutable/set.rb +583 -0
- data/lib/immutable/sorted_set.rb +1464 -0
- data/lib/immutable/trie.rb +338 -0
- data/lib/immutable/undefined.rb +5 -0
- data/lib/immutable/vector.rb +1539 -0
- data/lib/immutable/version.rb +5 -0
- data/spec/fixtures/io_spec.txt +3 -0
- data/spec/lib/immutable/core_ext/array_spec.rb +13 -0
- data/spec/lib/immutable/core_ext/enumerable_spec.rb +29 -0
- data/spec/lib/immutable/core_ext/io_spec.rb +28 -0
- data/spec/lib/immutable/deque/clear_spec.rb +33 -0
- data/spec/lib/immutable/deque/construction_spec.rb +29 -0
- data/spec/lib/immutable/deque/copying_spec.rb +19 -0
- data/spec/lib/immutable/deque/dequeue_spec.rb +34 -0
- data/spec/lib/immutable/deque/empty_spec.rb +39 -0
- data/spec/lib/immutable/deque/enqueue_spec.rb +27 -0
- data/spec/lib/immutable/deque/first_spec.rb +17 -0
- data/spec/lib/immutable/deque/inspect_spec.rb +23 -0
- data/spec/lib/immutable/deque/last_spec.rb +17 -0
- data/spec/lib/immutable/deque/marshal_spec.rb +33 -0
- data/spec/lib/immutable/deque/new_spec.rb +43 -0
- data/spec/lib/immutable/deque/pop_spec.rb +36 -0
- data/spec/lib/immutable/deque/pretty_print_spec.rb +23 -0
- data/spec/lib/immutable/deque/push_spec.rb +36 -0
- data/spec/lib/immutable/deque/random_modification_spec.rb +33 -0
- data/spec/lib/immutable/deque/shift_spec.rb +29 -0
- data/spec/lib/immutable/deque/size_spec.rb +19 -0
- data/spec/lib/immutable/deque/to_a_spec.rb +26 -0
- data/spec/lib/immutable/deque/to_ary_spec.rb +35 -0
- data/spec/lib/immutable/deque/to_list_spec.rb +24 -0
- data/spec/lib/immutable/deque/unshift_spec.rb +30 -0
- data/spec/lib/immutable/hash/all_spec.rb +53 -0
- data/spec/lib/immutable/hash/any_spec.rb +53 -0
- data/spec/lib/immutable/hash/assoc_spec.rb +51 -0
- data/spec/lib/immutable/hash/clear_spec.rb +42 -0
- data/spec/lib/immutable/hash/construction_spec.rb +38 -0
- data/spec/lib/immutable/hash/copying_spec.rb +13 -0
- data/spec/lib/immutable/hash/default_proc_spec.rb +72 -0
- data/spec/lib/immutable/hash/delete_spec.rb +39 -0
- data/spec/lib/immutable/hash/each_spec.rb +77 -0
- data/spec/lib/immutable/hash/each_with_index_spec.rb +29 -0
- data/spec/lib/immutable/hash/empty_spec.rb +43 -0
- data/spec/lib/immutable/hash/eql_spec.rb +69 -0
- data/spec/lib/immutable/hash/except_spec.rb +42 -0
- data/spec/lib/immutable/hash/fetch_spec.rb +57 -0
- data/spec/lib/immutable/hash/find_spec.rb +43 -0
- data/spec/lib/immutable/hash/flat_map_spec.rb +35 -0
- data/spec/lib/immutable/hash/flatten_spec.rb +98 -0
- data/spec/lib/immutable/hash/get_spec.rb +79 -0
- data/spec/lib/immutable/hash/has_key_spec.rb +31 -0
- data/spec/lib/immutable/hash/has_value_spec.rb +27 -0
- data/spec/lib/immutable/hash/hash_spec.rb +29 -0
- data/spec/lib/immutable/hash/inspect_spec.rb +30 -0
- data/spec/lib/immutable/hash/invert_spec.rb +30 -0
- data/spec/lib/immutable/hash/key_spec.rb +27 -0
- data/spec/lib/immutable/hash/keys_spec.rb +15 -0
- data/spec/lib/immutable/hash/map_spec.rb +45 -0
- data/spec/lib/immutable/hash/marshal_spec.rb +28 -0
- data/spec/lib/immutable/hash/merge_spec.rb +82 -0
- data/spec/lib/immutable/hash/min_max_spec.rb +45 -0
- data/spec/lib/immutable/hash/new_spec.rb +70 -0
- data/spec/lib/immutable/hash/none_spec.rb +48 -0
- data/spec/lib/immutable/hash/partition_spec.rb +35 -0
- data/spec/lib/immutable/hash/pretty_print_spec.rb +34 -0
- data/spec/lib/immutable/hash/put_spec.rb +102 -0
- data/spec/lib/immutable/hash/reduce_spec.rb +35 -0
- data/spec/lib/immutable/hash/reject_spec.rb +61 -0
- data/spec/lib/immutable/hash/reverse_each_spec.rb +27 -0
- data/spec/lib/immutable/hash/sample_spec.rb +13 -0
- data/spec/lib/immutable/hash/select_spec.rb +57 -0
- data/spec/lib/immutable/hash/size_spec.rb +51 -0
- data/spec/lib/immutable/hash/slice_spec.rb +44 -0
- data/spec/lib/immutable/hash/sort_spec.rb +26 -0
- data/spec/lib/immutable/hash/store_spec.rb +75 -0
- data/spec/lib/immutable/hash/take_spec.rb +35 -0
- data/spec/lib/immutable/hash/to_a_spec.rb +13 -0
- data/spec/lib/immutable/hash/to_hash_spec.rb +21 -0
- data/spec/lib/immutable/hash/update_in_spec.rb +79 -0
- data/spec/lib/immutable/hash/values_at_spec.rb +13 -0
- data/spec/lib/immutable/hash/values_spec.rb +23 -0
- data/spec/lib/immutable/list/add_spec.rb +25 -0
- data/spec/lib/immutable/list/all_spec.rb +57 -0
- data/spec/lib/immutable/list/any_spec.rb +49 -0
- data/spec/lib/immutable/list/append_spec.rb +38 -0
- data/spec/lib/immutable/list/at_spec.rb +29 -0
- data/spec/lib/immutable/list/break_spec.rb +69 -0
- data/spec/lib/immutable/list/cadr_spec.rb +38 -0
- data/spec/lib/immutable/list/chunk_spec.rb +28 -0
- data/spec/lib/immutable/list/clear_spec.rb +24 -0
- data/spec/lib/immutable/list/combination_spec.rb +33 -0
- data/spec/lib/immutable/list/compact_spec.rb +34 -0
- data/spec/lib/immutable/list/compare_spec.rb +30 -0
- data/spec/lib/immutable/list/cons_spec.rb +25 -0
- data/spec/lib/immutable/list/construction_spec.rb +110 -0
- data/spec/lib/immutable/list/copying_spec.rb +19 -0
- data/spec/lib/immutable/list/count_spec.rb +36 -0
- data/spec/lib/immutable/list/cycle_spec.rb +28 -0
- data/spec/lib/immutable/list/delete_at_spec.rb +18 -0
- data/spec/lib/immutable/list/delete_spec.rb +16 -0
- data/spec/lib/immutable/list/drop_spec.rb +30 -0
- data/spec/lib/immutable/list/drop_while_spec.rb +38 -0
- data/spec/lib/immutable/list/each_slice_spec.rb +51 -0
- data/spec/lib/immutable/list/each_spec.rb +40 -0
- data/spec/lib/immutable/list/each_with_index_spec.rb +28 -0
- data/spec/lib/immutable/list/empty_spec.rb +23 -0
- data/spec/lib/immutable/list/eql_spec.rb +61 -0
- data/spec/lib/immutable/list/fill_spec.rb +49 -0
- data/spec/lib/immutable/list/find_all_spec.rb +70 -0
- data/spec/lib/immutable/list/find_index_spec.rb +35 -0
- data/spec/lib/immutable/list/find_spec.rb +42 -0
- data/spec/lib/immutable/list/flat_map_spec.rb +51 -0
- data/spec/lib/immutable/list/flatten_spec.rb +30 -0
- data/spec/lib/immutable/list/grep_spec.rb +46 -0
- data/spec/lib/immutable/list/group_by_spec.rb +41 -0
- data/spec/lib/immutable/list/hash_spec.rb +21 -0
- data/spec/lib/immutable/list/head_spec.rb +19 -0
- data/spec/lib/immutable/list/include_spec.rb +35 -0
- data/spec/lib/immutable/list/index_spec.rb +33 -0
- data/spec/lib/immutable/list/indices_spec.rb +61 -0
- data/spec/lib/immutable/list/init_spec.rb +28 -0
- data/spec/lib/immutable/list/inits_spec.rb +28 -0
- data/spec/lib/immutable/list/insert_spec.rb +46 -0
- data/spec/lib/immutable/list/inspect_spec.rb +29 -0
- data/spec/lib/immutable/list/intersperse_spec.rb +28 -0
- data/spec/lib/immutable/list/join_spec.rb +63 -0
- data/spec/lib/immutable/list/last_spec.rb +23 -0
- data/spec/lib/immutable/list/ltlt_spec.rb +19 -0
- data/spec/lib/immutable/list/map_spec.rb +45 -0
- data/spec/lib/immutable/list/maximum_spec.rb +39 -0
- data/spec/lib/immutable/list/merge_by_spec.rb +51 -0
- data/spec/lib/immutable/list/merge_spec.rb +59 -0
- data/spec/lib/immutable/list/minimum_spec.rb +39 -0
- data/spec/lib/immutable/list/multithreading_spec.rb +47 -0
- data/spec/lib/immutable/list/none_spec.rb +47 -0
- data/spec/lib/immutable/list/one_spec.rb +49 -0
- data/spec/lib/immutable/list/partition_spec.rb +115 -0
- data/spec/lib/immutable/list/permutation_spec.rb +55 -0
- data/spec/lib/immutable/list/pop_spec.rb +25 -0
- data/spec/lib/immutable/list/product_spec.rb +23 -0
- data/spec/lib/immutable/list/reduce_spec.rb +53 -0
- data/spec/lib/immutable/list/reject_spec.rb +45 -0
- data/spec/lib/immutable/list/reverse_spec.rb +34 -0
- data/spec/lib/immutable/list/rotate_spec.rb +36 -0
- data/spec/lib/immutable/list/sample_spec.rb +13 -0
- data/spec/lib/immutable/list/select_spec.rb +70 -0
- data/spec/lib/immutable/list/size_spec.rb +25 -0
- data/spec/lib/immutable/list/slice_spec.rb +229 -0
- data/spec/lib/immutable/list/sorting_spec.rb +46 -0
- data/spec/lib/immutable/list/span_spec.rb +76 -0
- data/spec/lib/immutable/list/split_at_spec.rb +43 -0
- data/spec/lib/immutable/list/subsequences_spec.rb +23 -0
- data/spec/lib/immutable/list/sum_spec.rb +23 -0
- data/spec/lib/immutable/list/tail_spec.rb +30 -0
- data/spec/lib/immutable/list/tails_spec.rb +28 -0
- data/spec/lib/immutable/list/take_spec.rb +30 -0
- data/spec/lib/immutable/list/take_while_spec.rb +46 -0
- data/spec/lib/immutable/list/to_a_spec.rb +39 -0
- data/spec/lib/immutable/list/to_ary_spec.rb +41 -0
- data/spec/lib/immutable/list/to_list_spec.rb +19 -0
- data/spec/lib/immutable/list/to_set_spec.rb +17 -0
- data/spec/lib/immutable/list/transpose_spec.rb +19 -0
- data/spec/lib/immutable/list/union_spec.rb +31 -0
- data/spec/lib/immutable/list/uniq_spec.rb +35 -0
- data/spec/lib/immutable/list/zip_spec.rb +23 -0
- data/spec/lib/immutable/nested/construction_spec.rb +95 -0
- data/spec/lib/immutable/set/add_spec.rb +75 -0
- data/spec/lib/immutable/set/all_spec.rb +51 -0
- data/spec/lib/immutable/set/any_spec.rb +51 -0
- data/spec/lib/immutable/set/clear_spec.rb +33 -0
- data/spec/lib/immutable/set/compact_spec.rb +30 -0
- data/spec/lib/immutable/set/construction_spec.rb +18 -0
- data/spec/lib/immutable/set/copying_spec.rb +13 -0
- data/spec/lib/immutable/set/count_spec.rb +36 -0
- data/spec/lib/immutable/set/delete_spec.rb +71 -0
- data/spec/lib/immutable/set/difference_spec.rb +49 -0
- data/spec/lib/immutable/set/disjoint_spec.rb +25 -0
- data/spec/lib/immutable/set/each_spec.rb +45 -0
- data/spec/lib/immutable/set/empty_spec.rb +44 -0
- data/spec/lib/immutable/set/eqeq_spec.rb +103 -0
- data/spec/lib/immutable/set/eql_spec.rb +109 -0
- data/spec/lib/immutable/set/exclusion_spec.rb +47 -0
- data/spec/lib/immutable/set/find_spec.rb +35 -0
- data/spec/lib/immutable/set/first_spec.rb +28 -0
- data/spec/lib/immutable/set/flatten_spec.rb +46 -0
- data/spec/lib/immutable/set/grep_spec.rb +57 -0
- data/spec/lib/immutable/set/group_by_spec.rb +59 -0
- data/spec/lib/immutable/set/hash_spec.rb +22 -0
- data/spec/lib/immutable/set/include_spec.rb +60 -0
- data/spec/lib/immutable/set/inspect_spec.rb +47 -0
- data/spec/lib/immutable/set/intersect_spec.rb +25 -0
- data/spec/lib/immutable/set/intersection_spec.rb +52 -0
- data/spec/lib/immutable/set/join_spec.rb +64 -0
- data/spec/lib/immutable/set/map_spec.rb +59 -0
- data/spec/lib/immutable/set/marshal_spec.rb +28 -0
- data/spec/lib/immutable/set/maximum_spec.rb +36 -0
- data/spec/lib/immutable/set/minimum_spec.rb +36 -0
- data/spec/lib/immutable/set/new_spec.rb +53 -0
- data/spec/lib/immutable/set/none_spec.rb +47 -0
- data/spec/lib/immutable/set/one_spec.rb +47 -0
- data/spec/lib/immutable/set/partition_spec.rb +52 -0
- data/spec/lib/immutable/set/product_spec.rb +23 -0
- data/spec/lib/immutable/set/reduce_spec.rb +55 -0
- data/spec/lib/immutable/set/reject_spec.rb +50 -0
- data/spec/lib/immutable/set/reverse_each_spec.rb +38 -0
- data/spec/lib/immutable/set/sample_spec.rb +13 -0
- data/spec/lib/immutable/set/select_spec.rb +73 -0
- data/spec/lib/immutable/set/size_spec.rb +17 -0
- data/spec/lib/immutable/set/sorting_spec.rb +59 -0
- data/spec/lib/immutable/set/subset_spec.rb +51 -0
- data/spec/lib/immutable/set/sum_spec.rb +23 -0
- data/spec/lib/immutable/set/superset_spec.rb +51 -0
- data/spec/lib/immutable/set/to_a_spec.rb +30 -0
- data/spec/lib/immutable/set/to_list_spec.rb +35 -0
- data/spec/lib/immutable/set/to_set_spec.rb +19 -0
- data/spec/lib/immutable/set/union_spec.rb +63 -0
- data/spec/lib/immutable/sorted_set/above_spec.rb +51 -0
- data/spec/lib/immutable/sorted_set/add_spec.rb +62 -0
- data/spec/lib/immutable/sorted_set/at_spec.rb +24 -0
- data/spec/lib/immutable/sorted_set/below_spec.rb +51 -0
- data/spec/lib/immutable/sorted_set/between_spec.rb +51 -0
- data/spec/lib/immutable/sorted_set/clear_spec.rb +43 -0
- data/spec/lib/immutable/sorted_set/copying_spec.rb +20 -0
- data/spec/lib/immutable/sorted_set/delete_at_spec.rb +18 -0
- data/spec/lib/immutable/sorted_set/delete_spec.rb +89 -0
- data/spec/lib/immutable/sorted_set/difference_spec.rb +22 -0
- data/spec/lib/immutable/sorted_set/disjoint_spec.rb +25 -0
- data/spec/lib/immutable/sorted_set/drop_spec.rb +55 -0
- data/spec/lib/immutable/sorted_set/drop_while_spec.rb +34 -0
- data/spec/lib/immutable/sorted_set/each_spec.rb +28 -0
- data/spec/lib/immutable/sorted_set/empty_spec.rb +34 -0
- data/spec/lib/immutable/sorted_set/eql_spec.rb +120 -0
- data/spec/lib/immutable/sorted_set/exclusion_spec.rb +22 -0
- data/spec/lib/immutable/sorted_set/fetch_spec.rb +64 -0
- data/spec/lib/immutable/sorted_set/find_index_spec.rb +40 -0
- data/spec/lib/immutable/sorted_set/first_spec.rb +18 -0
- data/spec/lib/immutable/sorted_set/from_spec.rb +51 -0
- data/spec/lib/immutable/sorted_set/group_by_spec.rb +57 -0
- data/spec/lib/immutable/sorted_set/include_spec.rb +23 -0
- data/spec/lib/immutable/sorted_set/inspect_spec.rb +37 -0
- data/spec/lib/immutable/sorted_set/intersect_spec.rb +25 -0
- data/spec/lib/immutable/sorted_set/intersection_spec.rb +28 -0
- data/spec/lib/immutable/sorted_set/last_spec.rb +36 -0
- data/spec/lib/immutable/sorted_set/map_spec.rb +43 -0
- data/spec/lib/immutable/sorted_set/marshal_spec.rb +36 -0
- data/spec/lib/immutable/sorted_set/maximum_spec.rb +36 -0
- data/spec/lib/immutable/sorted_set/minimum_spec.rb +19 -0
- data/spec/lib/immutable/sorted_set/new_spec.rb +71 -0
- data/spec/lib/immutable/sorted_set/reverse_each_spec.rb +28 -0
- data/spec/lib/immutable/sorted_set/sample_spec.rb +13 -0
- data/spec/lib/immutable/sorted_set/select_spec.rb +61 -0
- data/spec/lib/immutable/sorted_set/size_spec.rb +17 -0
- data/spec/lib/immutable/sorted_set/slice_spec.rb +256 -0
- data/spec/lib/immutable/sorted_set/sorting_spec.rb +44 -0
- data/spec/lib/immutable/sorted_set/subset_spec.rb +47 -0
- data/spec/lib/immutable/sorted_set/superset_spec.rb +47 -0
- data/spec/lib/immutable/sorted_set/take_spec.rb +54 -0
- data/spec/lib/immutable/sorted_set/take_while_spec.rb +33 -0
- data/spec/lib/immutable/sorted_set/to_set_spec.rb +17 -0
- data/spec/lib/immutable/sorted_set/union_spec.rb +27 -0
- data/spec/lib/immutable/sorted_set/up_to_spec.rb +52 -0
- data/spec/lib/immutable/sorted_set/values_at_spec.rb +33 -0
- data/spec/lib/immutable/vector/add_spec.rb +67 -0
- data/spec/lib/immutable/vector/any_spec.rb +69 -0
- data/spec/lib/immutable/vector/assoc_spec.rb +45 -0
- data/spec/lib/immutable/vector/bsearch_spec.rb +65 -0
- data/spec/lib/immutable/vector/clear_spec.rb +33 -0
- data/spec/lib/immutable/vector/combination_spec.rb +81 -0
- data/spec/lib/immutable/vector/compact_spec.rb +29 -0
- data/spec/lib/immutable/vector/compare_spec.rb +31 -0
- data/spec/lib/immutable/vector/concat_spec.rb +34 -0
- data/spec/lib/immutable/vector/copying_spec.rb +20 -0
- data/spec/lib/immutable/vector/count_spec.rb +17 -0
- data/spec/lib/immutable/vector/delete_at_spec.rb +53 -0
- data/spec/lib/immutable/vector/delete_spec.rb +30 -0
- data/spec/lib/immutable/vector/drop_spec.rb +41 -0
- data/spec/lib/immutable/vector/drop_while_spec.rb +54 -0
- data/spec/lib/immutable/vector/each_index_spec.rb +40 -0
- data/spec/lib/immutable/vector/each_spec.rb +44 -0
- data/spec/lib/immutable/vector/each_with_index_spec.rb +39 -0
- data/spec/lib/immutable/vector/empty_spec.rb +41 -0
- data/spec/lib/immutable/vector/eql_spec.rb +76 -0
- data/spec/lib/immutable/vector/fetch_spec.rb +64 -0
- data/spec/lib/immutable/vector/fill_spec.rb +88 -0
- data/spec/lib/immutable/vector/first_spec.rb +18 -0
- data/spec/lib/immutable/vector/flat_map_spec.rb +50 -0
- data/spec/lib/immutable/vector/flatten_spec.rb +58 -0
- data/spec/lib/immutable/vector/get_spec.rb +74 -0
- data/spec/lib/immutable/vector/group_by_spec.rb +57 -0
- data/spec/lib/immutable/vector/include_spec.rb +30 -0
- data/spec/lib/immutable/vector/insert_spec.rb +68 -0
- data/spec/lib/immutable/vector/inspect_spec.rb +49 -0
- data/spec/lib/immutable/vector/join_spec.rb +58 -0
- data/spec/lib/immutable/vector/last_spec.rb +45 -0
- data/spec/lib/immutable/vector/length_spec.rb +45 -0
- data/spec/lib/immutable/vector/ltlt_spec.rb +65 -0
- data/spec/lib/immutable/vector/map_spec.rb +51 -0
- data/spec/lib/immutable/vector/marshal_spec.rb +31 -0
- data/spec/lib/immutable/vector/maximum_spec.rb +33 -0
- data/spec/lib/immutable/vector/minimum_spec.rb +33 -0
- data/spec/lib/immutable/vector/multiply_spec.rb +47 -0
- data/spec/lib/immutable/vector/new_spec.rb +50 -0
- data/spec/lib/immutable/vector/partition_spec.rb +52 -0
- data/spec/lib/immutable/vector/permutation_spec.rb +91 -0
- data/spec/lib/immutable/vector/pop_spec.rb +26 -0
- data/spec/lib/immutable/vector/product_spec.rb +70 -0
- data/spec/lib/immutable/vector/reduce_spec.rb +55 -0
- data/spec/lib/immutable/vector/reject_spec.rb +43 -0
- data/spec/lib/immutable/vector/repeated_combination_spec.rb +77 -0
- data/spec/lib/immutable/vector/repeated_permutation_spec.rb +93 -0
- data/spec/lib/immutable/vector/reverse_each_spec.rb +31 -0
- data/spec/lib/immutable/vector/reverse_spec.rb +21 -0
- data/spec/lib/immutable/vector/rindex_spec.rb +36 -0
- data/spec/lib/immutable/vector/rotate_spec.rb +73 -0
- data/spec/lib/immutable/vector/sample_spec.rb +13 -0
- data/spec/lib/immutable/vector/select_spec.rb +63 -0
- data/spec/lib/immutable/vector/set_spec.rb +174 -0
- data/spec/lib/immutable/vector/shift_spec.rb +27 -0
- data/spec/lib/immutable/vector/shuffle_spec.rb +43 -0
- data/spec/lib/immutable/vector/slice_spec.rb +240 -0
- data/spec/lib/immutable/vector/sorting_spec.rb +56 -0
- data/spec/lib/immutable/vector/sum_spec.rb +17 -0
- data/spec/lib/immutable/vector/take_spec.rb +42 -0
- data/spec/lib/immutable/vector/take_while_spec.rb +34 -0
- data/spec/lib/immutable/vector/to_a_spec.rb +41 -0
- data/spec/lib/immutable/vector/to_ary_spec.rb +34 -0
- data/spec/lib/immutable/vector/to_list_spec.rb +30 -0
- data/spec/lib/immutable/vector/to_set_spec.rb +21 -0
- data/spec/lib/immutable/vector/transpose_spec.rb +48 -0
- data/spec/lib/immutable/vector/uniq_spec.rb +76 -0
- data/spec/lib/immutable/vector/unshift_spec.rb +28 -0
- data/spec/lib/immutable/vector/update_in_spec.rb +82 -0
- data/spec/lib/immutable/vector/values_at_spec.rb +33 -0
- data/spec/lib/immutable/vector/zip_spec.rb +57 -0
- data/spec/lib/load_spec.rb +42 -0
- data/spec/spec_helper.rb +92 -0
- metadata +830 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: de7204bc2220b5743b2d8b3344d562377bd692a9
|
4
|
+
data.tar.gz: 965f9782b7d7a5b803f2ee76c3ef10d5f1203a2b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3e7a5faa17dfdbbcbf86ba190a30537cf9b52c7b571cee68158fed8bfa69be547aeb8af91d9f91efd875a7b21462a1f84efce0edab1283fd132b9e8e819122c2
|
7
|
+
data.tar.gz: b06f1d17c9f1159433c2db10a2a30788a02cf379f093da86b24e77ccefe04323582beef964dcf7d220e5c3e54ac7e98e40f794e87a408da07f9c2b38da59951b
|
data/lib/immutable.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require "immutable/list"
|
2
|
+
|
3
|
+
# Monkey-patches to Ruby's built-in `Enumerable` module.
|
4
|
+
# @see http://www.ruby-doc.org/core/Enumerable.html
|
5
|
+
module Enumerable
|
6
|
+
# Return a new {Immutable::List} populated with the items in this `Enumerable` object.
|
7
|
+
# @return [List]
|
8
|
+
def to_list
|
9
|
+
Immutable::List.from_enum(self)
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require "immutable/list"
|
2
|
+
|
3
|
+
# Monkey-patches to Ruby's built-in `IO` class.
|
4
|
+
# @see http://www.ruby-doc.org/core/IO.html
|
5
|
+
class IO
|
6
|
+
# Return a lazy list of "records" read from this IO stream.
|
7
|
+
# "Records" are delimited by `$/`, the global input record separator string.
|
8
|
+
# By default, it is `"\n"`, a newline.
|
9
|
+
#
|
10
|
+
# @return [List]
|
11
|
+
def to_list(sep = $/) # global input record separator
|
12
|
+
Immutable::LazyList.new do
|
13
|
+
line = gets(sep)
|
14
|
+
if line
|
15
|
+
Immutable::Cons.new(line, to_list)
|
16
|
+
else
|
17
|
+
EmptyList
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,254 @@
|
|
1
|
+
require "immutable/list"
|
2
|
+
|
3
|
+
module Immutable
|
4
|
+
|
5
|
+
# A `Deque` (or double-ended queue) is an ordered, sequential collection of
|
6
|
+
# objects, which allows elements to be retrieved, added and removed at the
|
7
|
+
# front and end of the sequence in constant time. This makes `Deque` perfect
|
8
|
+
# for use as an immutable queue or stack.
|
9
|
+
#
|
10
|
+
# A `Deque` differs from a {Vector} in that vectors allow indexed access to
|
11
|
+
# any element in the collection. `Deque`s only allow access to the first and
|
12
|
+
# last element. But adding and removing from the ends of a `Deque` is faster
|
13
|
+
# than adding and removing from the ends of a {Vector}.
|
14
|
+
#
|
15
|
+
# To create a new `Deque`:
|
16
|
+
#
|
17
|
+
# Immutable::Deque.new([:first, :second, :third])
|
18
|
+
# Immutable::Deque[1, 2, 3, 4, 5]
|
19
|
+
#
|
20
|
+
# Or you can start with an empty deque and build it up:
|
21
|
+
#
|
22
|
+
# Immutable::Deque.empty.push('b').push('c').unshift('a')
|
23
|
+
#
|
24
|
+
# Like all `immutable-ruby` collections, `Deque` is immutable. The four basic
|
25
|
+
# operations that "modify" deques ({#push}, {#pop}, {#shift}, and
|
26
|
+
# {#unshift}) all return a new collection and leave the existing one
|
27
|
+
# unchanged.
|
28
|
+
#
|
29
|
+
# @example
|
30
|
+
# deque = Immutable::Deque.empty # => Immutable::Deque[]
|
31
|
+
# deque = deque.push('a').push('b').push('c') # => Immutable::Deque['a', 'b', 'c']
|
32
|
+
# deque.first # => 'a'
|
33
|
+
# deque.last # => 'c'
|
34
|
+
# deque = deque.shift # => Immutable::Deque['b', 'c']
|
35
|
+
#
|
36
|
+
# @see http://en.wikipedia.org/wiki/Deque "Deque" on Wikipedia
|
37
|
+
#
|
38
|
+
class Deque
|
39
|
+
class << self
|
40
|
+
# Create a new `Deque` populated with the given items.
|
41
|
+
# @return [Deque]
|
42
|
+
def [](*items)
|
43
|
+
items.empty? ? empty : new(items)
|
44
|
+
end
|
45
|
+
|
46
|
+
# Return an empty `Deque`. If used on a subclass, returns an empty instance
|
47
|
+
# of that class.
|
48
|
+
#
|
49
|
+
# @return [Deque]
|
50
|
+
def empty
|
51
|
+
@empty ||= self.new
|
52
|
+
end
|
53
|
+
|
54
|
+
# "Raw" allocation of a new `Deque`. Used internally to create a new
|
55
|
+
# instance quickly after consing onto the front/rear lists or taking their
|
56
|
+
# tails.
|
57
|
+
#
|
58
|
+
# @return [Deque]
|
59
|
+
# @private
|
60
|
+
def alloc(front, rear)
|
61
|
+
result = allocate
|
62
|
+
result.instance_variable_set(:@front, front)
|
63
|
+
result.instance_variable_set(:@rear, rear)
|
64
|
+
result.freeze
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def initialize(items=[])
|
69
|
+
@front = List.from_enum(items)
|
70
|
+
@rear = EmptyList
|
71
|
+
freeze
|
72
|
+
end
|
73
|
+
|
74
|
+
# Return `true` if this `Deque` contains no items.
|
75
|
+
# @return [Boolean]
|
76
|
+
def empty?
|
77
|
+
@front.empty? && @rear.empty?
|
78
|
+
end
|
79
|
+
|
80
|
+
# Return the number of items in this `Deque`.
|
81
|
+
#
|
82
|
+
# @example
|
83
|
+
# Immutable::Deque["A", "B", "C"].size # => 3
|
84
|
+
#
|
85
|
+
# @return [Integer]
|
86
|
+
def size
|
87
|
+
@front.size + @rear.size
|
88
|
+
end
|
89
|
+
alias :length :size
|
90
|
+
|
91
|
+
# Return the first item in the `Deque`. If the deque is empty, return `nil`.
|
92
|
+
#
|
93
|
+
# @example
|
94
|
+
# Immutable::Deque["A", "B", "C"].first # => "A"
|
95
|
+
#
|
96
|
+
# @return [Object]
|
97
|
+
def first
|
98
|
+
return @front.head unless @front.empty?
|
99
|
+
@rear.last # memoize?
|
100
|
+
end
|
101
|
+
|
102
|
+
# Return the last item in the `Deque`. If the deque is empty, return `nil`.
|
103
|
+
#
|
104
|
+
# @example
|
105
|
+
# Immutable::Deque["A", "B", "C"].last # => "C"
|
106
|
+
#
|
107
|
+
# @return [Object]
|
108
|
+
def last
|
109
|
+
return @rear.head unless @rear.empty?
|
110
|
+
@front.last # memoize?
|
111
|
+
end
|
112
|
+
|
113
|
+
# Return a new `Deque` with `item` added at the end.
|
114
|
+
#
|
115
|
+
# @example
|
116
|
+
# Immutable::Deque["A", "B", "C"].add("Z")
|
117
|
+
# # => Immutable::Deque["A", "B", "C", "Z"]
|
118
|
+
#
|
119
|
+
# @param item [Object] The item to add
|
120
|
+
# @return [Deque]
|
121
|
+
def push(item)
|
122
|
+
self.class.alloc(@front, @rear.cons(item))
|
123
|
+
end
|
124
|
+
alias :enqueue :push
|
125
|
+
|
126
|
+
# Return a new `Deque` with the last item removed.
|
127
|
+
#
|
128
|
+
# @example
|
129
|
+
# Immutable::Deque["A", "B", "C"].pop
|
130
|
+
# # => Immutable::Deque["A", "B"]
|
131
|
+
#
|
132
|
+
# @return [Deque]
|
133
|
+
def pop
|
134
|
+
front, rear = @front, @rear
|
135
|
+
|
136
|
+
if rear.empty?
|
137
|
+
return self.class.empty if front.empty?
|
138
|
+
front, rear = EmptyList, front.reverse
|
139
|
+
end
|
140
|
+
|
141
|
+
self.class.alloc(front, rear.tail)
|
142
|
+
end
|
143
|
+
|
144
|
+
# Return a new `Deque` with `item` added at the front.
|
145
|
+
#
|
146
|
+
# @example
|
147
|
+
# Immutable::Deque["A", "B", "C"].unshift("Z")
|
148
|
+
# # => Immutable::Deque["Z", "A", "B", "C"]
|
149
|
+
#
|
150
|
+
# @param item [Object] The item to add
|
151
|
+
# @return [Deque]
|
152
|
+
def unshift(item)
|
153
|
+
self.class.alloc(@front.cons(item), @rear)
|
154
|
+
end
|
155
|
+
|
156
|
+
# Return a new `Deque` with the first item removed.
|
157
|
+
#
|
158
|
+
# @example
|
159
|
+
# Immutable::Deque["A", "B", "C"].shift
|
160
|
+
# # => Immutable::Deque["B", "C"]
|
161
|
+
#
|
162
|
+
# @return [Deque]
|
163
|
+
def shift
|
164
|
+
front, rear = @front, @rear
|
165
|
+
|
166
|
+
if front.empty?
|
167
|
+
return self.class.empty if rear.empty?
|
168
|
+
front, rear = rear.reverse, EmptyList
|
169
|
+
end
|
170
|
+
|
171
|
+
self.class.alloc(front.tail, rear)
|
172
|
+
end
|
173
|
+
alias :dequeue :shift
|
174
|
+
|
175
|
+
# Return an empty `Deque` instance, of the same class as this one. Useful if you
|
176
|
+
# have multiple subclasses of `Deque` and want to treat them polymorphically.
|
177
|
+
#
|
178
|
+
# @return [Deque]
|
179
|
+
def clear
|
180
|
+
self.class.empty
|
181
|
+
end
|
182
|
+
|
183
|
+
# Return true if `other` has the same type and contents as this `Deque`.
|
184
|
+
#
|
185
|
+
# @param other [Object] The collection to compare with
|
186
|
+
# @return [Boolean]
|
187
|
+
def eql?(other)
|
188
|
+
return true if other.equal?(self)
|
189
|
+
instance_of?(other.class) && to_ary.eql?(other.to_ary)
|
190
|
+
end
|
191
|
+
alias :== :eql?
|
192
|
+
|
193
|
+
# Return an `Array` with the same elements, in the same order.
|
194
|
+
# @return [Array]
|
195
|
+
def to_a
|
196
|
+
@front.to_a.concat(@rear.to_a.tap { |a| a.reverse! })
|
197
|
+
end
|
198
|
+
alias :entries :to_a
|
199
|
+
alias :to_ary :to_a
|
200
|
+
|
201
|
+
# Return a {List} with the same elements, in the same order.
|
202
|
+
# @return [Immutable::List]
|
203
|
+
def to_list
|
204
|
+
@front.append(@rear.reverse)
|
205
|
+
end
|
206
|
+
|
207
|
+
# Return the contents of this `Deque` as a programmer-readable `String`. If all the
|
208
|
+
# items in the deque are serializable as Ruby literal strings, the returned string can
|
209
|
+
# be passed to `eval` to reconstitute an equivalent `Deque`.
|
210
|
+
#
|
211
|
+
# @return [String]
|
212
|
+
def inspect
|
213
|
+
result = "#{self.class}["
|
214
|
+
i = 0
|
215
|
+
@front.each { |obj| result << ', ' if i > 0; result << obj.inspect; i += 1 }
|
216
|
+
@rear.to_a.tap { |a| a.reverse! }.each { |obj| result << ', ' if i > 0; result << obj.inspect; i += 1 }
|
217
|
+
result << "]"
|
218
|
+
end
|
219
|
+
|
220
|
+
# Return `self`. Since this is an immutable object duplicates are
|
221
|
+
# equivalent.
|
222
|
+
# @return [Deque]
|
223
|
+
def dup
|
224
|
+
self
|
225
|
+
end
|
226
|
+
alias :clone :dup
|
227
|
+
|
228
|
+
# @private
|
229
|
+
def pretty_print(pp)
|
230
|
+
pp.group(1, "#{self.class}[", "]") do
|
231
|
+
pp.breakable ''
|
232
|
+
pp.seplist(self.to_a) { |obj| obj.pretty_print(pp) }
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
236
|
+
# @return [::Array]
|
237
|
+
# @private
|
238
|
+
def marshal_dump
|
239
|
+
to_a
|
240
|
+
end
|
241
|
+
|
242
|
+
# @private
|
243
|
+
def marshal_load(array)
|
244
|
+
initialize(array)
|
245
|
+
end
|
246
|
+
end
|
247
|
+
|
248
|
+
# The canonical empty `Deque`. Returned by `Deque[]` when
|
249
|
+
# invoked with no arguments; also returned by `Deque.empty`. Prefer using this
|
250
|
+
# one rather than creating many empty deques using `Deque.new`.
|
251
|
+
#
|
252
|
+
# @private
|
253
|
+
EmptyDeque = Immutable::Deque.empty
|
254
|
+
end
|
@@ -0,0 +1,152 @@
|
|
1
|
+
module Immutable
|
2
|
+
|
3
|
+
# Helper module for immutable-ruby's sequential collections
|
4
|
+
#
|
5
|
+
# Classes including `Immutable::Enumerable` must implement:
|
6
|
+
#
|
7
|
+
# - `#each` (just like `::Enumerable`).
|
8
|
+
# - `#select`, which takes a block, and returns an instance of the same class
|
9
|
+
# with only the items for which the block returns a true value
|
10
|
+
module Enumerable
|
11
|
+
include ::Enumerable
|
12
|
+
|
13
|
+
# Return a new collection with all the elements for which the block returns false.
|
14
|
+
def reject
|
15
|
+
return enum_for(:reject) if not block_given?
|
16
|
+
select { |item| !yield(item) }
|
17
|
+
end
|
18
|
+
alias :delete_if :reject
|
19
|
+
|
20
|
+
# Return a new collection with all `nil` elements removed.
|
21
|
+
def compact
|
22
|
+
select { |item| !item.nil? }
|
23
|
+
end
|
24
|
+
|
25
|
+
# Search the collection for elements which are `#===` to `item`. Yield them to
|
26
|
+
# the optional code block if provided, and return them as a new collection.
|
27
|
+
def grep(pattern, &block)
|
28
|
+
result = select { |item| pattern === item }
|
29
|
+
result = result.map(&block) if block_given?
|
30
|
+
result
|
31
|
+
end
|
32
|
+
|
33
|
+
# Yield all integers from 0 up to, but not including, the number of items in
|
34
|
+
# this collection. For collections which provide indexed access, these are all
|
35
|
+
# the valid, non-negative indices into the collection.
|
36
|
+
def each_index(&block)
|
37
|
+
return enum_for(:each_index) unless block_given?
|
38
|
+
0.upto(size-1, &block)
|
39
|
+
self
|
40
|
+
end
|
41
|
+
|
42
|
+
# Multiply all the items (presumably numeric) in this collection together.
|
43
|
+
def product
|
44
|
+
reduce(1, &:*)
|
45
|
+
end
|
46
|
+
|
47
|
+
# Add up all the items (presumably numeric) in this collection.
|
48
|
+
def sum
|
49
|
+
reduce(0, &:+)
|
50
|
+
end
|
51
|
+
|
52
|
+
# Return 2 collections, the first containing all the elements for which the block
|
53
|
+
# evaluates to true, the second containing the rest.
|
54
|
+
def partition
|
55
|
+
return enum_for(:partition) if not block_given?
|
56
|
+
a,b = super
|
57
|
+
[self.class.new(a), self.class.new(b)].freeze
|
58
|
+
end
|
59
|
+
|
60
|
+
# Groups the collection into sub-collections by the result of yielding them to
|
61
|
+
# the block. Returns a {Hash} where the keys are return values from the block,
|
62
|
+
# and the values are sub-collections. All the sub-collections are built up from
|
63
|
+
# `empty_group`, which should respond to `#add` by returning a new collection
|
64
|
+
# with an added element.
|
65
|
+
def group_by_with(empty_group, &block)
|
66
|
+
block ||= lambda { |item| item }
|
67
|
+
reduce(Immutable::EmptyHash) do |hash, item|
|
68
|
+
key = block.call(item)
|
69
|
+
group = hash.get(key) || empty_group
|
70
|
+
hash.put(key, group.add(item))
|
71
|
+
end
|
72
|
+
end
|
73
|
+
protected :group_by_with
|
74
|
+
|
75
|
+
# Groups the collection into sub-collections by the result of yielding them to
|
76
|
+
# the block. Returns a {Hash} where the keys are return values from the block,
|
77
|
+
# and the values are sub-collections (of the same type as this one).
|
78
|
+
def group_by(&block)
|
79
|
+
group_by_with(self.class.empty, &block)
|
80
|
+
end
|
81
|
+
|
82
|
+
# Compare with `other`, and return 0, 1, or -1 if it is (respectively) equal to,
|
83
|
+
# greater than, or less than this collection.
|
84
|
+
def <=>(other)
|
85
|
+
return 0 if self.equal?(other)
|
86
|
+
enum1, enum2 = self.to_enum, other.to_enum
|
87
|
+
loop do
|
88
|
+
item1 = enum1.next
|
89
|
+
item2 = enum2.next
|
90
|
+
comp = (item1 <=> item2)
|
91
|
+
return comp if comp != 0
|
92
|
+
end
|
93
|
+
size1, size2 = self.size, other.size
|
94
|
+
return 0 if size1 == size2
|
95
|
+
size1 > size2 ? 1 : -1
|
96
|
+
end
|
97
|
+
|
98
|
+
# Return true if `other` contains the same elements, in the same order.
|
99
|
+
# @return [Boolean]
|
100
|
+
def ==(other)
|
101
|
+
self.eql?(other) || other.respond_to?(:to_ary) && to_ary.eql?(other.to_ary)
|
102
|
+
end
|
103
|
+
|
104
|
+
# Convert all the elements into strings and join them together, separated by
|
105
|
+
# `separator`. By default, the `separator` is `$,`, the global default string
|
106
|
+
# separator, which is normally `nil`.
|
107
|
+
def join(separator = $,)
|
108
|
+
result = ""
|
109
|
+
if separator
|
110
|
+
each_with_index { |obj, i| result << separator if i > 0; result << obj.to_s }
|
111
|
+
else
|
112
|
+
each { |obj| result << obj.to_s }
|
113
|
+
end
|
114
|
+
result
|
115
|
+
end
|
116
|
+
|
117
|
+
# Convert this collection to a {Set}.
|
118
|
+
def to_set
|
119
|
+
Immutable::Set.new(self)
|
120
|
+
end
|
121
|
+
|
122
|
+
# Convert this collection to a programmer-readable `String` representation.
|
123
|
+
def inspect
|
124
|
+
result = "#{self.class}["
|
125
|
+
each_with_index { |obj, i| result << ', ' if i > 0; result << obj.inspect }
|
126
|
+
result << "]"
|
127
|
+
end
|
128
|
+
|
129
|
+
# @private
|
130
|
+
def pretty_print(pp)
|
131
|
+
pp.group(1, "#{self.class}[", "]") do
|
132
|
+
pp.breakable ''
|
133
|
+
pp.seplist(self) { |obj| obj.pretty_print(pp) }
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
alias :to_ary :to_a
|
138
|
+
alias :index :find_index
|
139
|
+
|
140
|
+
## Compatibility fixes
|
141
|
+
|
142
|
+
if RUBY_ENGINE == 'rbx'
|
143
|
+
# Rubinius implements Enumerable#sort_by using Enumerable#map
|
144
|
+
# Because we do our own, custom implementations of #map, that doesn't work well
|
145
|
+
# @private
|
146
|
+
def sort_by(&block)
|
147
|
+
result = to_a
|
148
|
+
result.frozen? ? result.sort_by(&block) : result.sort_by!(&block)
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|