immutable-ruby 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (345) hide show
  1. checksums.yaml +5 -5
  2. data/lib/immutable/core_ext/enumerable.rb +1 -1
  3. data/lib/immutable/core_ext/io.rb +1 -1
  4. data/lib/immutable/core_ext.rb +2 -2
  5. data/lib/immutable/deque.rb +50 -15
  6. data/lib/immutable/enumerable.rb +19 -10
  7. data/lib/immutable/hash.rb +128 -28
  8. data/lib/immutable/list.rb +48 -48
  9. data/lib/immutable/nested.rb +10 -7
  10. data/lib/immutable/set.rb +30 -30
  11. data/lib/immutable/sorted_set.rb +77 -37
  12. data/lib/immutable/trie.rb +21 -29
  13. data/lib/immutable/vector.rb +61 -46
  14. data/lib/immutable/version.rb +1 -1
  15. data/lib/immutable.rb +9 -9
  16. metadata +44 -687
  17. data/spec/fixtures/io_spec.txt +0 -3
  18. data/spec/lib/immutable/core_ext/array_spec.rb +0 -13
  19. data/spec/lib/immutable/core_ext/enumerable_spec.rb +0 -29
  20. data/spec/lib/immutable/core_ext/io_spec.rb +0 -28
  21. data/spec/lib/immutable/deque/clear_spec.rb +0 -33
  22. data/spec/lib/immutable/deque/construction_spec.rb +0 -29
  23. data/spec/lib/immutable/deque/copying_spec.rb +0 -19
  24. data/spec/lib/immutable/deque/dequeue_spec.rb +0 -34
  25. data/spec/lib/immutable/deque/empty_spec.rb +0 -39
  26. data/spec/lib/immutable/deque/enqueue_spec.rb +0 -27
  27. data/spec/lib/immutable/deque/first_spec.rb +0 -17
  28. data/spec/lib/immutable/deque/inspect_spec.rb +0 -23
  29. data/spec/lib/immutable/deque/last_spec.rb +0 -17
  30. data/spec/lib/immutable/deque/marshal_spec.rb +0 -33
  31. data/spec/lib/immutable/deque/new_spec.rb +0 -43
  32. data/spec/lib/immutable/deque/pop_spec.rb +0 -36
  33. data/spec/lib/immutable/deque/pretty_print_spec.rb +0 -23
  34. data/spec/lib/immutable/deque/push_spec.rb +0 -36
  35. data/spec/lib/immutable/deque/random_modification_spec.rb +0 -33
  36. data/spec/lib/immutable/deque/shift_spec.rb +0 -29
  37. data/spec/lib/immutable/deque/size_spec.rb +0 -19
  38. data/spec/lib/immutable/deque/to_a_spec.rb +0 -26
  39. data/spec/lib/immutable/deque/to_ary_spec.rb +0 -35
  40. data/spec/lib/immutable/deque/to_list_spec.rb +0 -24
  41. data/spec/lib/immutable/deque/unshift_spec.rb +0 -30
  42. data/spec/lib/immutable/hash/all_spec.rb +0 -53
  43. data/spec/lib/immutable/hash/any_spec.rb +0 -53
  44. data/spec/lib/immutable/hash/assoc_spec.rb +0 -51
  45. data/spec/lib/immutable/hash/clear_spec.rb +0 -42
  46. data/spec/lib/immutable/hash/construction_spec.rb +0 -38
  47. data/spec/lib/immutable/hash/copying_spec.rb +0 -13
  48. data/spec/lib/immutable/hash/default_proc_spec.rb +0 -72
  49. data/spec/lib/immutable/hash/delete_spec.rb +0 -39
  50. data/spec/lib/immutable/hash/each_spec.rb +0 -77
  51. data/spec/lib/immutable/hash/each_with_index_spec.rb +0 -29
  52. data/spec/lib/immutable/hash/empty_spec.rb +0 -43
  53. data/spec/lib/immutable/hash/eql_spec.rb +0 -69
  54. data/spec/lib/immutable/hash/except_spec.rb +0 -42
  55. data/spec/lib/immutable/hash/fetch_spec.rb +0 -57
  56. data/spec/lib/immutable/hash/find_spec.rb +0 -43
  57. data/spec/lib/immutable/hash/flat_map_spec.rb +0 -35
  58. data/spec/lib/immutable/hash/flatten_spec.rb +0 -98
  59. data/spec/lib/immutable/hash/get_spec.rb +0 -79
  60. data/spec/lib/immutable/hash/has_key_spec.rb +0 -31
  61. data/spec/lib/immutable/hash/has_value_spec.rb +0 -27
  62. data/spec/lib/immutable/hash/hash_spec.rb +0 -29
  63. data/spec/lib/immutable/hash/inspect_spec.rb +0 -30
  64. data/spec/lib/immutable/hash/invert_spec.rb +0 -30
  65. data/spec/lib/immutable/hash/key_spec.rb +0 -27
  66. data/spec/lib/immutable/hash/keys_spec.rb +0 -15
  67. data/spec/lib/immutable/hash/map_spec.rb +0 -45
  68. data/spec/lib/immutable/hash/marshal_spec.rb +0 -28
  69. data/spec/lib/immutable/hash/merge_spec.rb +0 -82
  70. data/spec/lib/immutable/hash/min_max_spec.rb +0 -45
  71. data/spec/lib/immutable/hash/new_spec.rb +0 -70
  72. data/spec/lib/immutable/hash/none_spec.rb +0 -48
  73. data/spec/lib/immutable/hash/partition_spec.rb +0 -35
  74. data/spec/lib/immutable/hash/pretty_print_spec.rb +0 -34
  75. data/spec/lib/immutable/hash/put_spec.rb +0 -102
  76. data/spec/lib/immutable/hash/reduce_spec.rb +0 -35
  77. data/spec/lib/immutable/hash/reject_spec.rb +0 -61
  78. data/spec/lib/immutable/hash/reverse_each_spec.rb +0 -27
  79. data/spec/lib/immutable/hash/sample_spec.rb +0 -13
  80. data/spec/lib/immutable/hash/select_spec.rb +0 -57
  81. data/spec/lib/immutable/hash/size_spec.rb +0 -51
  82. data/spec/lib/immutable/hash/slice_spec.rb +0 -44
  83. data/spec/lib/immutable/hash/sort_spec.rb +0 -26
  84. data/spec/lib/immutable/hash/store_spec.rb +0 -75
  85. data/spec/lib/immutable/hash/take_spec.rb +0 -35
  86. data/spec/lib/immutable/hash/to_a_spec.rb +0 -13
  87. data/spec/lib/immutable/hash/to_hash_spec.rb +0 -21
  88. data/spec/lib/immutable/hash/update_in_spec.rb +0 -79
  89. data/spec/lib/immutable/hash/values_at_spec.rb +0 -13
  90. data/spec/lib/immutable/hash/values_spec.rb +0 -23
  91. data/spec/lib/immutable/list/add_spec.rb +0 -25
  92. data/spec/lib/immutable/list/all_spec.rb +0 -57
  93. data/spec/lib/immutable/list/any_spec.rb +0 -49
  94. data/spec/lib/immutable/list/append_spec.rb +0 -38
  95. data/spec/lib/immutable/list/at_spec.rb +0 -29
  96. data/spec/lib/immutable/list/break_spec.rb +0 -69
  97. data/spec/lib/immutable/list/cadr_spec.rb +0 -38
  98. data/spec/lib/immutable/list/chunk_spec.rb +0 -28
  99. data/spec/lib/immutable/list/clear_spec.rb +0 -24
  100. data/spec/lib/immutable/list/combination_spec.rb +0 -33
  101. data/spec/lib/immutable/list/compact_spec.rb +0 -34
  102. data/spec/lib/immutable/list/compare_spec.rb +0 -30
  103. data/spec/lib/immutable/list/cons_spec.rb +0 -25
  104. data/spec/lib/immutable/list/construction_spec.rb +0 -110
  105. data/spec/lib/immutable/list/copying_spec.rb +0 -19
  106. data/spec/lib/immutable/list/count_spec.rb +0 -36
  107. data/spec/lib/immutable/list/cycle_spec.rb +0 -28
  108. data/spec/lib/immutable/list/delete_at_spec.rb +0 -18
  109. data/spec/lib/immutable/list/delete_spec.rb +0 -16
  110. data/spec/lib/immutable/list/drop_spec.rb +0 -30
  111. data/spec/lib/immutable/list/drop_while_spec.rb +0 -38
  112. data/spec/lib/immutable/list/each_slice_spec.rb +0 -51
  113. data/spec/lib/immutable/list/each_spec.rb +0 -40
  114. data/spec/lib/immutable/list/each_with_index_spec.rb +0 -28
  115. data/spec/lib/immutable/list/empty_spec.rb +0 -23
  116. data/spec/lib/immutable/list/eql_spec.rb +0 -61
  117. data/spec/lib/immutable/list/fill_spec.rb +0 -49
  118. data/spec/lib/immutable/list/find_all_spec.rb +0 -70
  119. data/spec/lib/immutable/list/find_index_spec.rb +0 -35
  120. data/spec/lib/immutable/list/find_spec.rb +0 -42
  121. data/spec/lib/immutable/list/flat_map_spec.rb +0 -51
  122. data/spec/lib/immutable/list/flatten_spec.rb +0 -30
  123. data/spec/lib/immutable/list/grep_spec.rb +0 -46
  124. data/spec/lib/immutable/list/group_by_spec.rb +0 -41
  125. data/spec/lib/immutable/list/hash_spec.rb +0 -21
  126. data/spec/lib/immutable/list/head_spec.rb +0 -19
  127. data/spec/lib/immutable/list/include_spec.rb +0 -35
  128. data/spec/lib/immutable/list/index_spec.rb +0 -33
  129. data/spec/lib/immutable/list/indices_spec.rb +0 -61
  130. data/spec/lib/immutable/list/init_spec.rb +0 -28
  131. data/spec/lib/immutable/list/inits_spec.rb +0 -28
  132. data/spec/lib/immutable/list/insert_spec.rb +0 -46
  133. data/spec/lib/immutable/list/inspect_spec.rb +0 -29
  134. data/spec/lib/immutable/list/intersperse_spec.rb +0 -28
  135. data/spec/lib/immutable/list/join_spec.rb +0 -63
  136. data/spec/lib/immutable/list/last_spec.rb +0 -23
  137. data/spec/lib/immutable/list/ltlt_spec.rb +0 -19
  138. data/spec/lib/immutable/list/map_spec.rb +0 -45
  139. data/spec/lib/immutable/list/maximum_spec.rb +0 -39
  140. data/spec/lib/immutable/list/merge_by_spec.rb +0 -51
  141. data/spec/lib/immutable/list/merge_spec.rb +0 -59
  142. data/spec/lib/immutable/list/minimum_spec.rb +0 -39
  143. data/spec/lib/immutable/list/multithreading_spec.rb +0 -47
  144. data/spec/lib/immutable/list/none_spec.rb +0 -47
  145. data/spec/lib/immutable/list/one_spec.rb +0 -49
  146. data/spec/lib/immutable/list/partition_spec.rb +0 -115
  147. data/spec/lib/immutable/list/permutation_spec.rb +0 -55
  148. data/spec/lib/immutable/list/pop_spec.rb +0 -25
  149. data/spec/lib/immutable/list/product_spec.rb +0 -23
  150. data/spec/lib/immutable/list/reduce_spec.rb +0 -53
  151. data/spec/lib/immutable/list/reject_spec.rb +0 -45
  152. data/spec/lib/immutable/list/reverse_spec.rb +0 -34
  153. data/spec/lib/immutable/list/rotate_spec.rb +0 -36
  154. data/spec/lib/immutable/list/sample_spec.rb +0 -13
  155. data/spec/lib/immutable/list/select_spec.rb +0 -70
  156. data/spec/lib/immutable/list/size_spec.rb +0 -25
  157. data/spec/lib/immutable/list/slice_spec.rb +0 -229
  158. data/spec/lib/immutable/list/sorting_spec.rb +0 -46
  159. data/spec/lib/immutable/list/span_spec.rb +0 -76
  160. data/spec/lib/immutable/list/split_at_spec.rb +0 -43
  161. data/spec/lib/immutable/list/subsequences_spec.rb +0 -23
  162. data/spec/lib/immutable/list/sum_spec.rb +0 -23
  163. data/spec/lib/immutable/list/tail_spec.rb +0 -30
  164. data/spec/lib/immutable/list/tails_spec.rb +0 -28
  165. data/spec/lib/immutable/list/take_spec.rb +0 -30
  166. data/spec/lib/immutable/list/take_while_spec.rb +0 -46
  167. data/spec/lib/immutable/list/to_a_spec.rb +0 -39
  168. data/spec/lib/immutable/list/to_ary_spec.rb +0 -41
  169. data/spec/lib/immutable/list/to_list_spec.rb +0 -19
  170. data/spec/lib/immutable/list/to_set_spec.rb +0 -17
  171. data/spec/lib/immutable/list/transpose_spec.rb +0 -19
  172. data/spec/lib/immutable/list/union_spec.rb +0 -31
  173. data/spec/lib/immutable/list/uniq_spec.rb +0 -35
  174. data/spec/lib/immutable/list/zip_spec.rb +0 -23
  175. data/spec/lib/immutable/nested/construction_spec.rb +0 -95
  176. data/spec/lib/immutable/set/add_spec.rb +0 -75
  177. data/spec/lib/immutable/set/all_spec.rb +0 -51
  178. data/spec/lib/immutable/set/any_spec.rb +0 -51
  179. data/spec/lib/immutable/set/clear_spec.rb +0 -33
  180. data/spec/lib/immutable/set/compact_spec.rb +0 -30
  181. data/spec/lib/immutable/set/construction_spec.rb +0 -18
  182. data/spec/lib/immutable/set/copying_spec.rb +0 -13
  183. data/spec/lib/immutable/set/count_spec.rb +0 -36
  184. data/spec/lib/immutable/set/delete_spec.rb +0 -71
  185. data/spec/lib/immutable/set/difference_spec.rb +0 -49
  186. data/spec/lib/immutable/set/disjoint_spec.rb +0 -25
  187. data/spec/lib/immutable/set/each_spec.rb +0 -45
  188. data/spec/lib/immutable/set/empty_spec.rb +0 -44
  189. data/spec/lib/immutable/set/eqeq_spec.rb +0 -103
  190. data/spec/lib/immutable/set/eql_spec.rb +0 -109
  191. data/spec/lib/immutable/set/exclusion_spec.rb +0 -47
  192. data/spec/lib/immutable/set/find_spec.rb +0 -35
  193. data/spec/lib/immutable/set/first_spec.rb +0 -28
  194. data/spec/lib/immutable/set/flatten_spec.rb +0 -46
  195. data/spec/lib/immutable/set/grep_spec.rb +0 -57
  196. data/spec/lib/immutable/set/group_by_spec.rb +0 -59
  197. data/spec/lib/immutable/set/hash_spec.rb +0 -22
  198. data/spec/lib/immutable/set/include_spec.rb +0 -60
  199. data/spec/lib/immutable/set/inspect_spec.rb +0 -47
  200. data/spec/lib/immutable/set/intersect_spec.rb +0 -25
  201. data/spec/lib/immutable/set/intersection_spec.rb +0 -52
  202. data/spec/lib/immutable/set/join_spec.rb +0 -64
  203. data/spec/lib/immutable/set/map_spec.rb +0 -59
  204. data/spec/lib/immutable/set/marshal_spec.rb +0 -28
  205. data/spec/lib/immutable/set/maximum_spec.rb +0 -36
  206. data/spec/lib/immutable/set/minimum_spec.rb +0 -36
  207. data/spec/lib/immutable/set/new_spec.rb +0 -53
  208. data/spec/lib/immutable/set/none_spec.rb +0 -47
  209. data/spec/lib/immutable/set/one_spec.rb +0 -47
  210. data/spec/lib/immutable/set/partition_spec.rb +0 -52
  211. data/spec/lib/immutable/set/product_spec.rb +0 -23
  212. data/spec/lib/immutable/set/reduce_spec.rb +0 -55
  213. data/spec/lib/immutable/set/reject_spec.rb +0 -50
  214. data/spec/lib/immutable/set/reverse_each_spec.rb +0 -38
  215. data/spec/lib/immutable/set/sample_spec.rb +0 -13
  216. data/spec/lib/immutable/set/select_spec.rb +0 -73
  217. data/spec/lib/immutable/set/size_spec.rb +0 -17
  218. data/spec/lib/immutable/set/sorting_spec.rb +0 -59
  219. data/spec/lib/immutable/set/subset_spec.rb +0 -51
  220. data/spec/lib/immutable/set/sum_spec.rb +0 -23
  221. data/spec/lib/immutable/set/superset_spec.rb +0 -51
  222. data/spec/lib/immutable/set/to_a_spec.rb +0 -30
  223. data/spec/lib/immutable/set/to_list_spec.rb +0 -35
  224. data/spec/lib/immutable/set/to_set_spec.rb +0 -19
  225. data/spec/lib/immutable/set/union_spec.rb +0 -63
  226. data/spec/lib/immutable/sorted_set/above_spec.rb +0 -51
  227. data/spec/lib/immutable/sorted_set/add_spec.rb +0 -62
  228. data/spec/lib/immutable/sorted_set/at_spec.rb +0 -24
  229. data/spec/lib/immutable/sorted_set/below_spec.rb +0 -51
  230. data/spec/lib/immutable/sorted_set/between_spec.rb +0 -51
  231. data/spec/lib/immutable/sorted_set/clear_spec.rb +0 -43
  232. data/spec/lib/immutable/sorted_set/copying_spec.rb +0 -20
  233. data/spec/lib/immutable/sorted_set/delete_at_spec.rb +0 -18
  234. data/spec/lib/immutable/sorted_set/delete_spec.rb +0 -89
  235. data/spec/lib/immutable/sorted_set/difference_spec.rb +0 -22
  236. data/spec/lib/immutable/sorted_set/disjoint_spec.rb +0 -25
  237. data/spec/lib/immutable/sorted_set/drop_spec.rb +0 -55
  238. data/spec/lib/immutable/sorted_set/drop_while_spec.rb +0 -34
  239. data/spec/lib/immutable/sorted_set/each_spec.rb +0 -28
  240. data/spec/lib/immutable/sorted_set/empty_spec.rb +0 -34
  241. data/spec/lib/immutable/sorted_set/eql_spec.rb +0 -120
  242. data/spec/lib/immutable/sorted_set/exclusion_spec.rb +0 -22
  243. data/spec/lib/immutable/sorted_set/fetch_spec.rb +0 -64
  244. data/spec/lib/immutable/sorted_set/find_index_spec.rb +0 -40
  245. data/spec/lib/immutable/sorted_set/first_spec.rb +0 -18
  246. data/spec/lib/immutable/sorted_set/from_spec.rb +0 -51
  247. data/spec/lib/immutable/sorted_set/group_by_spec.rb +0 -57
  248. data/spec/lib/immutable/sorted_set/include_spec.rb +0 -23
  249. data/spec/lib/immutable/sorted_set/inspect_spec.rb +0 -37
  250. data/spec/lib/immutable/sorted_set/intersect_spec.rb +0 -25
  251. data/spec/lib/immutable/sorted_set/intersection_spec.rb +0 -28
  252. data/spec/lib/immutable/sorted_set/last_spec.rb +0 -36
  253. data/spec/lib/immutable/sorted_set/map_spec.rb +0 -43
  254. data/spec/lib/immutable/sorted_set/marshal_spec.rb +0 -36
  255. data/spec/lib/immutable/sorted_set/maximum_spec.rb +0 -36
  256. data/spec/lib/immutable/sorted_set/minimum_spec.rb +0 -19
  257. data/spec/lib/immutable/sorted_set/new_spec.rb +0 -71
  258. data/spec/lib/immutable/sorted_set/reverse_each_spec.rb +0 -28
  259. data/spec/lib/immutable/sorted_set/sample_spec.rb +0 -13
  260. data/spec/lib/immutable/sorted_set/select_spec.rb +0 -61
  261. data/spec/lib/immutable/sorted_set/size_spec.rb +0 -17
  262. data/spec/lib/immutable/sorted_set/slice_spec.rb +0 -256
  263. data/spec/lib/immutable/sorted_set/sorting_spec.rb +0 -44
  264. data/spec/lib/immutable/sorted_set/subset_spec.rb +0 -47
  265. data/spec/lib/immutable/sorted_set/superset_spec.rb +0 -47
  266. data/spec/lib/immutable/sorted_set/take_spec.rb +0 -54
  267. data/spec/lib/immutable/sorted_set/take_while_spec.rb +0 -33
  268. data/spec/lib/immutable/sorted_set/to_set_spec.rb +0 -17
  269. data/spec/lib/immutable/sorted_set/union_spec.rb +0 -27
  270. data/spec/lib/immutable/sorted_set/up_to_spec.rb +0 -52
  271. data/spec/lib/immutable/sorted_set/values_at_spec.rb +0 -33
  272. data/spec/lib/immutable/vector/add_spec.rb +0 -67
  273. data/spec/lib/immutable/vector/any_spec.rb +0 -69
  274. data/spec/lib/immutable/vector/assoc_spec.rb +0 -45
  275. data/spec/lib/immutable/vector/bsearch_spec.rb +0 -65
  276. data/spec/lib/immutable/vector/clear_spec.rb +0 -33
  277. data/spec/lib/immutable/vector/combination_spec.rb +0 -81
  278. data/spec/lib/immutable/vector/compact_spec.rb +0 -29
  279. data/spec/lib/immutable/vector/compare_spec.rb +0 -31
  280. data/spec/lib/immutable/vector/concat_spec.rb +0 -34
  281. data/spec/lib/immutable/vector/copying_spec.rb +0 -20
  282. data/spec/lib/immutable/vector/count_spec.rb +0 -17
  283. data/spec/lib/immutable/vector/delete_at_spec.rb +0 -53
  284. data/spec/lib/immutable/vector/delete_spec.rb +0 -30
  285. data/spec/lib/immutable/vector/drop_spec.rb +0 -41
  286. data/spec/lib/immutable/vector/drop_while_spec.rb +0 -54
  287. data/spec/lib/immutable/vector/each_index_spec.rb +0 -40
  288. data/spec/lib/immutable/vector/each_spec.rb +0 -44
  289. data/spec/lib/immutable/vector/each_with_index_spec.rb +0 -39
  290. data/spec/lib/immutable/vector/empty_spec.rb +0 -41
  291. data/spec/lib/immutable/vector/eql_spec.rb +0 -76
  292. data/spec/lib/immutable/vector/fetch_spec.rb +0 -64
  293. data/spec/lib/immutable/vector/fill_spec.rb +0 -88
  294. data/spec/lib/immutable/vector/first_spec.rb +0 -18
  295. data/spec/lib/immutable/vector/flat_map_spec.rb +0 -50
  296. data/spec/lib/immutable/vector/flatten_spec.rb +0 -58
  297. data/spec/lib/immutable/vector/get_spec.rb +0 -74
  298. data/spec/lib/immutable/vector/group_by_spec.rb +0 -57
  299. data/spec/lib/immutable/vector/include_spec.rb +0 -30
  300. data/spec/lib/immutable/vector/insert_spec.rb +0 -68
  301. data/spec/lib/immutable/vector/inspect_spec.rb +0 -49
  302. data/spec/lib/immutable/vector/join_spec.rb +0 -58
  303. data/spec/lib/immutable/vector/last_spec.rb +0 -45
  304. data/spec/lib/immutable/vector/length_spec.rb +0 -45
  305. data/spec/lib/immutable/vector/ltlt_spec.rb +0 -65
  306. data/spec/lib/immutable/vector/map_spec.rb +0 -51
  307. data/spec/lib/immutable/vector/marshal_spec.rb +0 -31
  308. data/spec/lib/immutable/vector/maximum_spec.rb +0 -33
  309. data/spec/lib/immutable/vector/minimum_spec.rb +0 -33
  310. data/spec/lib/immutable/vector/multiply_spec.rb +0 -47
  311. data/spec/lib/immutable/vector/new_spec.rb +0 -50
  312. data/spec/lib/immutable/vector/partition_spec.rb +0 -52
  313. data/spec/lib/immutable/vector/permutation_spec.rb +0 -91
  314. data/spec/lib/immutable/vector/pop_spec.rb +0 -26
  315. data/spec/lib/immutable/vector/product_spec.rb +0 -70
  316. data/spec/lib/immutable/vector/reduce_spec.rb +0 -55
  317. data/spec/lib/immutable/vector/reject_spec.rb +0 -43
  318. data/spec/lib/immutable/vector/repeated_combination_spec.rb +0 -77
  319. data/spec/lib/immutable/vector/repeated_permutation_spec.rb +0 -93
  320. data/spec/lib/immutable/vector/reverse_each_spec.rb +0 -31
  321. data/spec/lib/immutable/vector/reverse_spec.rb +0 -21
  322. data/spec/lib/immutable/vector/rindex_spec.rb +0 -36
  323. data/spec/lib/immutable/vector/rotate_spec.rb +0 -73
  324. data/spec/lib/immutable/vector/sample_spec.rb +0 -13
  325. data/spec/lib/immutable/vector/select_spec.rb +0 -63
  326. data/spec/lib/immutable/vector/set_spec.rb +0 -174
  327. data/spec/lib/immutable/vector/shift_spec.rb +0 -27
  328. data/spec/lib/immutable/vector/shuffle_spec.rb +0 -43
  329. data/spec/lib/immutable/vector/slice_spec.rb +0 -240
  330. data/spec/lib/immutable/vector/sorting_spec.rb +0 -56
  331. data/spec/lib/immutable/vector/sum_spec.rb +0 -17
  332. data/spec/lib/immutable/vector/take_spec.rb +0 -42
  333. data/spec/lib/immutable/vector/take_while_spec.rb +0 -34
  334. data/spec/lib/immutable/vector/to_a_spec.rb +0 -41
  335. data/spec/lib/immutable/vector/to_ary_spec.rb +0 -34
  336. data/spec/lib/immutable/vector/to_list_spec.rb +0 -30
  337. data/spec/lib/immutable/vector/to_set_spec.rb +0 -21
  338. data/spec/lib/immutable/vector/transpose_spec.rb +0 -48
  339. data/spec/lib/immutable/vector/uniq_spec.rb +0 -76
  340. data/spec/lib/immutable/vector/unshift_spec.rb +0 -28
  341. data/spec/lib/immutable/vector/update_in_spec.rb +0 -82
  342. data/spec/lib/immutable/vector/values_at_spec.rb +0 -33
  343. data/spec/lib/immutable/vector/zip_spec.rb +0 -57
  344. data/spec/lib/load_spec.rb +0 -42
  345. data/spec/spec_helper.rb +0 -92
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: de7204bc2220b5743b2d8b3344d562377bd692a9
4
- data.tar.gz: 965f9782b7d7a5b803f2ee76c3ef10d5f1203a2b
2
+ SHA256:
3
+ metadata.gz: 54e4768953f4e1a9afbfc0d8496bdb563ae850419c905ea4dce78b560c88da3c
4
+ data.tar.gz: 9237a022ed3107aad98adfaed510cbd4b76367b06aab7a2d6a1f8dc2d6d3c911
5
5
  SHA512:
6
- metadata.gz: 3e7a5faa17dfdbbcbf86ba190a30537cf9b52c7b571cee68158fed8bfa69be547aeb8af91d9f91efd875a7b21462a1f84efce0edab1283fd132b9e8e819122c2
7
- data.tar.gz: b06f1d17c9f1159433c2db10a2a30788a02cf379f093da86b24e77ccefe04323582beef964dcf7d220e5c3e54ac7e98e40f794e87a408da07f9c2b38da59951b
6
+ metadata.gz: 7aa2208347fcce032af7b0885cb5088ea7d93573dd54c59fbebf7d98bd962be8880533c3c0fabe92fb7cfc5eddf1a9cc06cb60a0180ee55507d09dde7b2a0396
7
+ data.tar.gz: f10991e1881c42941d9723eb0acc569126b06716273852089c7f25a3bf2e5fefc25e1d5c767682dbb75d88a52da9dc12aee90627c7e1a92cf513f586aab3ef42
@@ -1,4 +1,4 @@
1
- require "immutable/list"
1
+ require 'immutable/list'
2
2
 
3
3
  # Monkey-patches to Ruby's built-in `Enumerable` module.
4
4
  # @see http://www.ruby-doc.org/core/Enumerable.html
@@ -1,4 +1,4 @@
1
- require "immutable/list"
1
+ require 'immutable/list'
2
2
 
3
3
  # Monkey-patches to Ruby's built-in `IO` class.
4
4
  # @see http://www.ruby-doc.org/core/IO.html
@@ -1,2 +1,2 @@
1
- require "immutable/core_ext/enumerable"
2
- require "immutable/core_ext/io"
1
+ require 'immutable/core_ext/enumerable'
2
+ require 'immutable/core_ext/io'
@@ -1,4 +1,4 @@
1
- require "immutable/list"
1
+ require 'immutable/list'
2
2
 
3
3
  module Immutable
4
4
 
@@ -48,7 +48,7 @@ module Immutable
48
48
  #
49
49
  # @return [Deque]
50
50
  def empty
51
- @empty ||= self.new
51
+ @empty ||= new
52
52
  end
53
53
 
54
54
  # "Raw" allocation of a new `Deque`. Used internally to create a new
@@ -86,7 +86,7 @@ module Immutable
86
86
  def size
87
87
  @front.size + @rear.size
88
88
  end
89
- alias :length :size
89
+ alias length size
90
90
 
91
91
  # Return the first item in the `Deque`. If the deque is empty, return `nil`.
92
92
  #
@@ -110,10 +110,38 @@ module Immutable
110
110
  @front.last # memoize?
111
111
  end
112
112
 
113
+ # Return a new `Deque` with elements rotated by `n` positions.
114
+ # A positive rotation moves elements to the right, negative to the left, and 0 is a no-op.
115
+ #
116
+ # @example
117
+ # Immutable::Deque["A", "B", "C"].rotate(1)
118
+ # # => Immutable::Deque["C", "A", "B"]
119
+ # Immutable::Deque["A", "B", "C"].rotate(-1)
120
+ # # => Immutable::Deque["B", "C", "A"]
121
+ #
122
+ # @param n [Integer] number of positions to move elements by
123
+ # @return [Deque]
124
+ def rotate(n)
125
+ return self.class.empty if empty?
126
+
127
+ n %= size
128
+ return self if n == 0
129
+
130
+ a, b = @front, @rear
131
+
132
+ if b.size >= n
133
+ n.times { a = a.cons(b.head); b = b.tail }
134
+ else
135
+ (size - n).times { b = b.cons(a.head); a = a.tail }
136
+ end
137
+
138
+ self.class.alloc(a, b)
139
+ end
140
+
113
141
  # Return a new `Deque` with `item` added at the end.
114
142
  #
115
143
  # @example
116
- # Immutable::Deque["A", "B", "C"].add("Z")
144
+ # Immutable::Deque["A", "B", "C"].push("Z")
117
145
  # # => Immutable::Deque["A", "B", "C", "Z"]
118
146
  #
119
147
  # @param item [Object] The item to add
@@ -121,7 +149,7 @@ module Immutable
121
149
  def push(item)
122
150
  self.class.alloc(@front, @rear.cons(item))
123
151
  end
124
- alias :enqueue :push
152
+ alias enqueue push
125
153
 
126
154
  # Return a new `Deque` with the last item removed.
127
155
  #
@@ -170,7 +198,7 @@ module Immutable
170
198
 
171
199
  self.class.alloc(front.tail, rear)
172
200
  end
173
- alias :dequeue :shift
201
+ alias dequeue shift
174
202
 
175
203
  # Return an empty `Deque` instance, of the same class as this one. Useful if you
176
204
  # have multiple subclasses of `Deque` and want to treat them polymorphically.
@@ -180,6 +208,13 @@ module Immutable
180
208
  self.class.empty
181
209
  end
182
210
 
211
+ # Return a new `Deque` with the same items, but in reverse order.
212
+ #
213
+ # @return [Deque]
214
+ def reverse
215
+ self.class.alloc(@rear, @front)
216
+ end
217
+
183
218
  # Return true if `other` has the same type and contents as this `Deque`.
184
219
  #
185
220
  # @param other [Object] The collection to compare with
@@ -188,15 +223,15 @@ module Immutable
188
223
  return true if other.equal?(self)
189
224
  instance_of?(other.class) && to_ary.eql?(other.to_ary)
190
225
  end
191
- alias :== :eql?
226
+ alias == eql?
192
227
 
193
228
  # Return an `Array` with the same elements, in the same order.
194
229
  # @return [Array]
195
230
  def to_a
196
- @front.to_a.concat(@rear.to_a.tap { |a| a.reverse! })
231
+ @front.to_a.concat(@rear.to_a.tap(&:reverse!))
197
232
  end
198
- alias :entries :to_a
199
- alias :to_ary :to_a
233
+ alias entries to_a
234
+ alias to_ary to_a
200
235
 
201
236
  # Return a {List} with the same elements, in the same order.
202
237
  # @return [Immutable::List]
@@ -213,8 +248,8 @@ module Immutable
213
248
  result = "#{self.class}["
214
249
  i = 0
215
250
  @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 << "]"
251
+ @rear.to_a.tap(&:reverse!).each { |obj| result << ', ' if i > 0; result << obj.inspect; i += 1 }
252
+ result << ']'
218
253
  end
219
254
 
220
255
  # Return `self`. Since this is an immutable object duplicates are
@@ -223,13 +258,13 @@ module Immutable
223
258
  def dup
224
259
  self
225
260
  end
226
- alias :clone :dup
261
+ alias clone dup
227
262
 
228
263
  # @private
229
264
  def pretty_print(pp)
230
- pp.group(1, "#{self.class}[", "]") do
265
+ pp.group(1, "#{self.class}[", ']') do
231
266
  pp.breakable ''
232
- pp.seplist(self.to_a) { |obj| obj.pretty_print(pp) }
267
+ pp.seplist(to_a) { |obj| obj.pretty_print(pp) }
233
268
  end
234
269
  end
235
270
 
@@ -15,7 +15,7 @@ module Immutable
15
15
  return enum_for(:reject) if not block_given?
16
16
  select { |item| !yield(item) }
17
17
  end
18
- alias :delete_if :reject
18
+ alias delete_if reject
19
19
 
20
20
  # Return a new collection with all `nil` elements removed.
21
21
  def compact
@@ -30,6 +30,15 @@ module Immutable
30
30
  result
31
31
  end
32
32
 
33
+ # Search the collection for elements which are not `#===` to `item`. Yield
34
+ # them to the optional code block if provided, and return them as a new
35
+ # collection.
36
+ def grep_v(pattern, &block)
37
+ result = select { |item| !(pattern === item) }
38
+ result = result.map(&block) if block_given?
39
+ result
40
+ end
41
+
33
42
  # Yield all integers from 0 up to, but not including, the number of items in
34
43
  # this collection. For collections which provide indexed access, these are all
35
44
  # the valid, non-negative indices into the collection.
@@ -82,15 +91,15 @@ module Immutable
82
91
  # Compare with `other`, and return 0, 1, or -1 if it is (respectively) equal to,
83
92
  # greater than, or less than this collection.
84
93
  def <=>(other)
85
- return 0 if self.equal?(other)
86
- enum1, enum2 = self.to_enum, other.to_enum
94
+ return 0 if equal?(other)
95
+ enum1, enum2 = to_enum, other.to_enum
87
96
  loop do
88
97
  item1 = enum1.next
89
98
  item2 = enum2.next
90
99
  comp = (item1 <=> item2)
91
100
  return comp if comp != 0
92
101
  end
93
- size1, size2 = self.size, other.size
102
+ size1, size2 = size, other.size
94
103
  return 0 if size1 == size2
95
104
  size1 > size2 ? 1 : -1
96
105
  end
@@ -98,14 +107,14 @@ module Immutable
98
107
  # Return true if `other` contains the same elements, in the same order.
99
108
  # @return [Boolean]
100
109
  def ==(other)
101
- self.eql?(other) || other.respond_to?(:to_ary) && to_ary.eql?(other.to_ary)
110
+ eql?(other) || (other.respond_to?(:to_ary) && to_ary == other.to_ary)
102
111
  end
103
112
 
104
113
  # Convert all the elements into strings and join them together, separated by
105
114
  # `separator`. By default, the `separator` is `$,`, the global default string
106
115
  # separator, which is normally `nil`.
107
116
  def join(separator = $,)
108
- result = ""
117
+ result = ''
109
118
  if separator
110
119
  each_with_index { |obj, i| result << separator if i > 0; result << obj.to_s }
111
120
  else
@@ -123,19 +132,19 @@ module Immutable
123
132
  def inspect
124
133
  result = "#{self.class}["
125
134
  each_with_index { |obj, i| result << ', ' if i > 0; result << obj.inspect }
126
- result << "]"
135
+ result << ']'
127
136
  end
128
137
 
129
138
  # @private
130
139
  def pretty_print(pp)
131
- pp.group(1, "#{self.class}[", "]") do
140
+ pp.group(1, "#{self.class}[", ']') do
132
141
  pp.breakable ''
133
142
  pp.seplist(self) { |obj| obj.pretty_print(pp) }
134
143
  end
135
144
  end
136
145
 
137
- alias :to_ary :to_a
138
- alias :index :find_index
146
+ alias to_ary to_a
147
+ alias index find_index
139
148
 
140
149
  ## Compatibility fixes
141
150
 
@@ -1,8 +1,8 @@
1
- require "immutable/undefined"
2
- require "immutable/enumerable"
3
- require "immutable/trie"
4
- require "immutable/set"
5
- require "immutable/vector"
1
+ require 'immutable/undefined'
2
+ require 'immutable/enumerable'
3
+ require 'immutable/trie'
4
+ require 'immutable/set'
5
+ require 'immutable/vector'
6
6
 
7
7
  module Immutable
8
8
 
@@ -78,7 +78,7 @@ module Immutable
78
78
  #
79
79
  # @return [Hash]
80
80
  def empty
81
- @empty ||= self.new
81
+ @empty ||= new
82
82
  end
83
83
 
84
84
  # "Raw" allocation of a new `Hash`. Used internally to create a new
@@ -119,7 +119,7 @@ module Immutable
119
119
  def size
120
120
  @trie.size
121
121
  end
122
- alias :length :size
122
+ alias length size
123
123
 
124
124
  # Return `true` if this `Hash` contains no key/value pairs.
125
125
  #
@@ -140,9 +140,9 @@ module Immutable
140
140
  def key?(key)
141
141
  @trie.key?(key)
142
142
  end
143
- alias :has_key? :key?
144
- alias :include? :key?
145
- alias :member? :key?
143
+ alias has_key? key?
144
+ alias include? key?
145
+ alias member? key?
146
146
 
147
147
  # Return `true` if this `Hash` has one or more keys which map to the provided value.
148
148
  #
@@ -155,7 +155,7 @@ module Immutable
155
155
  each { |k,v| return true if value == v }
156
156
  false
157
157
  end
158
- alias :has_value? :value?
158
+ alias has_value? value?
159
159
 
160
160
  # Retrieve the value corresponding to the provided key object. If not found, and
161
161
  # this `Hash` has a default block, the default block is called to provide the
@@ -182,7 +182,7 @@ module Immutable
182
182
  @default.call(key)
183
183
  end
184
184
  end
185
- alias :[] :get
185
+ alias [] get
186
186
 
187
187
  # Retrieve the value corresponding to the given key object, or use the provided
188
188
  # default value or block, or otherwise raise a `KeyError`.
@@ -264,6 +264,12 @@ module Immutable
264
264
  end
265
265
  end
266
266
 
267
+ # @private
268
+ # @raise NoMethodError
269
+ def []=(*)
270
+ raise NoMethodError, "Immutable::Hash doesn't support `[]='; use `put' instead"
271
+ end
272
+
267
273
  # Return a new `Hash` with a deeply nested value modified to the result of
268
274
  # the given code block. When traversing the nested `Hash`es and `Vector`s,
269
275
  # non-existing keys are created with empty `Hash` values.
@@ -287,7 +293,7 @@ module Immutable
287
293
  # @return [Hash]
288
294
  def update_in(*key_path, &block)
289
295
  if key_path.empty?
290
- raise ArgumentError, "must have at least one key in path"
296
+ raise ArgumentError, 'must have at least one key in path'
291
297
  end
292
298
  key = key_path[0]
293
299
  if key_path.size == 1
@@ -342,7 +348,7 @@ module Immutable
342
348
  @trie.each(&block)
343
349
  self
344
350
  end
345
- alias :each_pair :each
351
+ alias each_pair each
346
352
 
347
353
  # Call the block once for each key/value pair in this `Hash`, passing the key/value
348
354
  # pair as parameters. Iteration order will be the opposite of {#each}.
@@ -417,7 +423,7 @@ module Immutable
417
423
  return self if empty?
418
424
  self.class.new(super, &@default)
419
425
  end
420
- alias :collect :map
426
+ alias collect map
421
427
 
422
428
  # Return a new `Hash` with all the key/value pairs for which the block returns true.
423
429
  #
@@ -433,8 +439,8 @@ module Immutable
433
439
  return enum_for(:select) unless block_given?
434
440
  derive_new_hash(@trie.select(&block))
435
441
  end
436
- alias :find_all :select
437
- alias :keep_if :select
442
+ alias find_all select
443
+ alias keep_if select
438
444
 
439
445
  # Yield `[key, value]` pairs until one is found for which the block returns true.
440
446
  # Return that `[key, value]` pair. If the block never returns true, return `nil`.
@@ -452,7 +458,7 @@ module Immutable
452
458
  each { |entry| return entry if yield entry }
453
459
  nil
454
460
  end
455
- alias :detect :find
461
+ alias detect find
456
462
 
457
463
  # Return a new `Hash` containing all the key/value pairs from this `Hash` and
458
464
  # `other`. If no block is provided, the value for entries with colliding keys
@@ -479,7 +485,7 @@ module Immutable
479
485
  def merge(other)
480
486
  trie = if block_given?
481
487
  other.reduce(@trie) do |trie, (key, value)|
482
- if entry = trie.get(key)
488
+ if (entry = trie.get(key))
483
489
  trie.put(key, yield(key, entry[1], value))
484
490
  else
485
491
  trie.put(key, value)
@@ -570,20 +576,54 @@ module Immutable
570
576
  end
571
577
 
572
578
  # Return a {Vector} of the values which correspond to the `wanted` keys.
573
- # If any of the `wanted` keys are not present in this `Hash`, they will be skipped.
579
+ # If any of the `wanted` keys are not present in this `Hash`, `nil` will be
580
+ # placed instead, or the result of the default proc (if one is defined),
581
+ # similar to the behavior of {#get}.
574
582
  #
575
583
  # @example
576
584
  # h = Immutable::Hash["A" => 1, "B" => 2, "C" => 3]
577
- # h.values_at("B", "A", "D") # => Immutable::Vector[2, 1]
585
+ # h.values_at("B", "A", "D") # => Immutable::Vector[2, 1, nil]
578
586
  #
579
587
  # @param wanted [Array] The keys to retrieve
580
588
  # @return [Vector]
581
589
  def values_at(*wanted)
582
- array = []
583
- wanted.each { |key| array << get(key) if key?(key) }
590
+ Vector.new(wanted.map { |key| get(key) }.freeze)
591
+ end
592
+
593
+ # Return a {Vector} of the values which correspond to the `wanted` keys.
594
+ # If any of the `wanted` keys are not present in this `Hash`, raise `KeyError`
595
+ # exception.
596
+ #
597
+ # @example
598
+ # h = Immutable::Hash["A" => 1, "B" => 2, "C" => 3]
599
+ # h.fetch_values("C", "A") # => Immutable::Vector[3, 1]
600
+ # h.fetch_values("C", "Z") # => KeyError: key not found: "Z"
601
+ #
602
+ # @param wanted [Array] The keys to retrieve
603
+ # @return [Vector]
604
+ def fetch_values(*wanted)
605
+ array = wanted.map { |key| fetch(key) }
584
606
  Vector.new(array.freeze)
585
607
  end
586
608
 
609
+ # Return the value of successively indexing into a nested collection.
610
+ # If any of the keys is not present, return `nil`.
611
+ #
612
+ # @example
613
+ # h = Immutable::Hash[a: 9, b: Immutable::Hash[c: 'a', d: 4], e: nil]
614
+ # h.dig(:b, :c) # => "a"
615
+ # h.dig(:b, :f) # => nil
616
+ #
617
+ # @return [Object]
618
+ def dig(key, *rest)
619
+ value = self[key]
620
+ if rest.empty? || value.nil?
621
+ value
622
+ else
623
+ value.dig(*rest)
624
+ end
625
+ end
626
+
587
627
  # Return a new {Set} containing the keys from this `Hash`.
588
628
  #
589
629
  # @example
@@ -731,7 +771,51 @@ module Immutable
731
771
  # @param other [Object] The object to compare with
732
772
  # @return [Boolean]
733
773
  def ==(other)
734
- self.eql?(other) || (other.respond_to?(:to_hash) && to_hash.eql?(other.to_hash))
774
+ eql?(other) || (other.respond_to?(:to_hash) && to_hash == other.to_hash)
775
+ end
776
+
777
+ # Return true if this `Hash` is a proper superset of `other`, which means
778
+ # all `other`'s keys are contained in this `Hash` with identical
779
+ # values, and the two hashes are not identical.
780
+ #
781
+ # @param other [Immutable::Hash] The object to compare with
782
+ # @return [Boolean]
783
+ def >(other)
784
+ self != other && self >= other
785
+ end
786
+
787
+ # Return true if this `Hash` is a superset of `other`, which means all
788
+ # `other`'s keys are contained in this `Hash` with identical values.
789
+ #
790
+ # @param other [Immutable::Hash] The object to compare with
791
+ # @return [Boolean]
792
+ def >=(other)
793
+ other.each do |key, value|
794
+ if self[key] != value
795
+ return false
796
+ end
797
+ end
798
+ true
799
+ end
800
+
801
+ # Return true if this `Hash` is a proper subset of `other`, which means all
802
+ # its keys are contained in `other` with the identical values, and the two
803
+ # hashes are not identical.
804
+ #
805
+ # @param other [Immutable::Hash] The object to compare with
806
+ # @return [Boolean]
807
+ def <(other)
808
+ other > self
809
+ end
810
+
811
+ # Return true if this `Hash` is a subset of `other`, which means all its
812
+ # keys are contained in `other` with the identical values, and the two
813
+ # hashes are not identical.
814
+ #
815
+ # @param other [Immutable::Hash] The object to compare with
816
+ # @return [Boolean]
817
+ def <=(other)
818
+ other >= self
735
819
  end
736
820
 
737
821
  # See `Object#hash`.
@@ -756,7 +840,7 @@ module Immutable
756
840
  result << key.inspect << ' => ' << val.inspect
757
841
  i += 1
758
842
  end
759
- result << "]"
843
+ result << ']'
760
844
  end
761
845
 
762
846
  # Return `self`. Since this is an immutable object duplicates are
@@ -765,7 +849,7 @@ module Immutable
765
849
  def dup
766
850
  self
767
851
  end
768
- alias :clone :dup
852
+ alias clone dup
769
853
 
770
854
  # Allows this `Hash` to be printed at the `pry` console, or using `pp` (from the
771
855
  # Ruby standard library), in a way which takes the amount of horizontal space on
@@ -774,7 +858,7 @@ module Immutable
774
858
  #
775
859
  # @private
776
860
  def pretty_print(pp)
777
- pp.group(1, "#{self.class}[", "]") do
861
+ pp.group(1, "#{self.class}[", ']') do
778
862
  pp.breakable ''
779
863
  pp.seplist(self, nil) do |key, val|
780
864
  pp.group do
@@ -799,7 +883,23 @@ module Immutable
799
883
  end
800
884
  output
801
885
  end
802
- alias :to_h :to_hash
886
+ alias to_h to_hash
887
+
888
+ # Return a `Proc` which accepts a key as an argument and returns the value.
889
+ # The `Proc` behaves like {#get} (when the key is missing, it returns nil or
890
+ # the result of the default proc).
891
+ #
892
+ # @example
893
+ # h = Immutable::Hash["A" => 1, "B" => 2, "C" => 3]
894
+ # h.to_proc.call("B")
895
+ # # => 2
896
+ # ["A", "C", "X"].map(&h) # The & is short for .to_proc in Ruby
897
+ # # => [1, 3, nil]
898
+ #
899
+ # @return [Proc]
900
+ def to_proc
901
+ lambda { |key| get(key) }
902
+ end
803
903
 
804
904
  # @return [::Hash]
805
905
  # @private