immutable-ruby 0.0.1 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
@@ -1,8 +1,7 @@
1
- require "immutable/enumerable"
2
- require "immutable/hash"
1
+ require 'immutable/enumerable'
2
+ require 'immutable/hash'
3
3
 
4
4
  module Immutable
5
-
6
5
  # A `Vector` is an ordered, integer-indexed collection of objects. Like
7
6
  # Ruby's `Array`, `Vector` indexing starts at zero and negative indexes count
8
7
  # back from the end.
@@ -48,7 +47,7 @@ module Immutable
48
47
  # Return the number of items in this `Vector`
49
48
  # @return [Integer]
50
49
  attr_reader :size
51
- alias :length :size
50
+ alias length size
52
51
 
53
52
  class << self
54
53
  # Create a new `Vector` populated with the given items.
@@ -62,7 +61,7 @@ module Immutable
62
61
  #
63
62
  # @return [Vector]
64
63
  def empty
65
- @empty ||= self.new
64
+ @empty ||= new
66
65
  end
67
66
 
68
67
  # "Raw" allocation of a new `Vector`. Used internally to create a new
@@ -132,8 +131,8 @@ module Immutable
132
131
  def add(item)
133
132
  update_root(@size, item)
134
133
  end
135
- alias :<< :add
136
- alias :push :add
134
+ alias << add
135
+ alias push add
137
136
 
138
137
  # Return a new `Vector` with a new value at the given `index`. If `index`
139
138
  # is greater than the length of the vector, the returned vector will be
@@ -197,7 +196,7 @@ module Immutable
197
196
  # @return [Vector]
198
197
  def update_in(*key_path, &block)
199
198
  if key_path.empty?
200
- raise ArgumentError, "must have at least one key in path"
199
+ raise ArgumentError, 'must have at least one key in path'
201
200
  end
202
201
  key = key_path[0]
203
202
  if key_path.size == 1
@@ -226,7 +225,7 @@ module Immutable
226
225
  return nil if index >= @size || index < 0
227
226
  leaf_node_for(@root, @levels * BITS_PER_LEVEL, index)[index & INDEX_MASK]
228
227
  end
229
- alias :at :get
228
+ alias at get
230
229
 
231
230
  # Retrieve the value at `index` with optional default.
232
231
  #
@@ -279,6 +278,24 @@ module Immutable
279
278
  end
280
279
  end
281
280
 
281
+ # Return the value of successively indexing into a nested collection.
282
+ # If any of the keys is not present, return `nil`.
283
+ #
284
+ # @example
285
+ # v = Immutable::Vector[9, Immutable::Hash[c: 'a', d: 4]]
286
+ # v.dig(1, :c) # => "a"
287
+ # v.dig(1, :f) # => nil
288
+ #
289
+ # @return [Object]
290
+ def dig(key, *rest)
291
+ value = self[key]
292
+ if rest.empty? || value.nil?
293
+ value
294
+ else
295
+ value.dig(*rest)
296
+ end
297
+ end
298
+
282
299
  # Return specific objects from the `Vector`. All overloads return `nil` if
283
300
  # the starting index is out of range.
284
301
  #
@@ -337,7 +354,7 @@ module Immutable
337
354
  subsequence(arg, length)
338
355
  end
339
356
  end
340
- alias :[] :slice
357
+ alias [] slice
341
358
 
342
359
  # Return a new `Vector` with the given values inserted before the element
343
360
  # at `index`. If `index` is greater than the current length, `nil` values
@@ -384,7 +401,7 @@ module Immutable
384
401
  index += @size if index < 0
385
402
 
386
403
  suffix = flatten_suffix(@root, @levels * BITS_PER_LEVEL, index, [])
387
- replace_suffix(index, suffix.tap { |a| a.shift })
404
+ replace_suffix(index, suffix.tap(&:shift))
388
405
  end
389
406
 
390
407
  # Return a new `Vector` with the last element removed. Return `self` if
@@ -472,8 +489,8 @@ module Immutable
472
489
  return enum_for(:select) unless block_given?
473
490
  reduce(self.class.empty) { |vector, item| yield(item) ? vector.add(item) : vector }
474
491
  end
475
- alias :find_all :select
476
- alias :keep_if :select
492
+ alias find_all select
493
+ alias keep_if select
477
494
 
478
495
  # Return a new `Vector` with all items which are equal to `obj` removed.
479
496
  # `#==` is used for checking equality.
@@ -500,7 +517,7 @@ module Immutable
500
517
  return self if empty?
501
518
  self.class.new(super)
502
519
  end
503
- alias :collect :map
520
+ alias collect map
504
521
 
505
522
  # Return a new `Vector` with the concatenated results of running the block once
506
523
  # for every element in this `Vector`.
@@ -535,18 +552,10 @@ module Immutable
535
552
  #
536
553
  # @return [Vector]
537
554
  def uniq(&block)
538
- array = self.to_a
539
- if block_given?
540
- if array.frozen?
541
- self.class.new(array.uniq(&block).freeze)
542
- elsif array.uniq!(&block) # returns nil if no changes were made
543
- self.class.new(array.freeze)
544
- else
545
- self
546
- end
547
- elsif array.frozen?
548
- self.class.new(array.uniq.freeze)
549
- elsif array.uniq! # returns nil if no changes were made
555
+ array = to_a
556
+ if array.frozen?
557
+ self.class.new(array.uniq(&block).freeze)
558
+ elsif array.uniq!(&block) # returns nil if no changes were made
550
559
  self.class.new(array.freeze)
551
560
  else
552
561
  self
@@ -599,7 +608,7 @@ module Immutable
599
608
  # @return [Vector]
600
609
  def flatten(level = -1)
601
610
  return self if level == 0
602
- array = self.to_a
611
+ array = to_a
603
612
  if array.frozen?
604
613
  self.class.new(array.flatten(level).freeze)
605
614
  elsif array.flatten!(level) # returns nil if no changes were made
@@ -623,7 +632,7 @@ module Immutable
623
632
  other = other.dup if other.frozen?
624
633
  replace_suffix(@size, other)
625
634
  end
626
- alias :concat :+
635
+ alias concat +
627
636
 
628
637
  # Combine two vectors by "zipping" them together. `others` should be arrays
629
638
  # and/or vectors. The corresponding elements from this `Vector` and each of
@@ -711,7 +720,7 @@ module Immutable
711
720
  def drop(n)
712
721
  return self if n == 0
713
722
  return self.class.empty if n >= @size
714
- raise ArgumentError, "attempt to drop negative size" if n < 0
723
+ raise ArgumentError, 'attempt to drop negative size' if n < 0
715
724
  self.class.new(flatten_suffix(@root, @levels * BITS_PER_LEVEL, n, []))
716
725
  end
717
726
 
@@ -852,7 +861,7 @@ module Immutable
852
861
  elsif n == 1
853
862
  each { |item| yield [item] }
854
863
  elsif n == @size
855
- yield self.to_a
864
+ yield to_a
856
865
  else
857
866
  combos = lambda do |result,index,remaining|
858
867
  while @size - index > remaining
@@ -959,15 +968,14 @@ module Immutable
959
968
  used, result = [], []
960
969
  perms = lambda do |index|
961
970
  0.upto(@size-1) do |i|
962
- if !used[i]
963
- result[index] = get(i)
964
- if index < n-1
965
- used[i] = true
966
- perms[index+1]
967
- used[i] = false
968
- else
969
- yield result.dup
970
- end
971
+ next if used[i]
972
+ result[index] = get(i)
973
+ if index < n-1
974
+ used[i] = true
975
+ perms[index+1]
976
+ used[i] = false
977
+ else
978
+ yield result.dup
971
979
  end
972
980
  end
973
981
  end
@@ -1075,13 +1083,13 @@ module Immutable
1075
1083
  end
1076
1084
 
1077
1085
  if block_given?
1078
- while true
1086
+ loop do
1079
1087
  yield build_array[]
1080
1088
  return self if bump_counters[]
1081
1089
  end
1082
1090
  else
1083
1091
  result = []
1084
- while true
1092
+ loop do
1085
1093
  result << build_array[]
1086
1094
  return result if bump_counters[]
1087
1095
  end
@@ -1104,7 +1112,7 @@ module Immutable
1104
1112
  #
1105
1113
  # @return [Vector]
1106
1114
  # @raise [IndexError] if elements are not of the same size.
1107
- # @raise [TypeError] if an element can not be implicitly converted to an array (using `#to_ary`)
1115
+ # @raise [TypeError] if an element does not respond to #size and #[]
1108
1116
  def transpose
1109
1117
  return self.class.empty if empty?
1110
1118
  result = Array.new(first.size) { [] }
@@ -1122,6 +1130,13 @@ module Immutable
1122
1130
 
1123
1131
  result.map! { |a| self.class.new(a) }
1124
1132
  self.class.new(result)
1133
+ rescue NoMethodError
1134
+ if any? { |x| !x.respond_to?(:size) || !x.respond_to?(:[]) }
1135
+ bad = find { |x| !x.respond_to?(:size) || !x.respond_to?(:[]) }
1136
+ raise TypeError, "'#{bad.inspect}' must respond to #size and #[] to be transposed"
1137
+ else
1138
+ raise
1139
+ end
1125
1140
  end
1126
1141
 
1127
1142
  # Finds a value from this `Vector` which meets the condition defined by the
@@ -1291,7 +1306,7 @@ module Immutable
1291
1306
  flatten_node(@root, @levels * BITS_PER_LEVEL, [])
1292
1307
  end
1293
1308
  end
1294
- alias :to_ary :to_a
1309
+ alias to_ary to_a
1295
1310
 
1296
1311
  # Return true if `other` has the same type and contents as this `Vector`.
1297
1312
  #
@@ -1315,7 +1330,7 @@ module Immutable
1315
1330
  def dup
1316
1331
  self
1317
1332
  end
1318
- alias :clone :dup
1333
+ alias clone dup
1319
1334
 
1320
1335
  # @return [::Array]
1321
1336
  # @private
@@ -1444,7 +1459,7 @@ module Immutable
1444
1459
  from_slot.upto(node.size-1) do |i|
1445
1460
  flatten_node(node[i], bitshift - BITS_PER_LEVEL, result)
1446
1461
  end
1447
- elsif child = node[from_slot]
1462
+ elsif (child = node[from_slot])
1448
1463
  flatten_suffix(child, bitshift - BITS_PER_LEVEL, from, result)
1449
1464
  (from_slot+1).upto(node.size-1) do |i|
1450
1465
  flatten_node(node[i], bitshift - BITS_PER_LEVEL, result)
@@ -1514,7 +1529,7 @@ module Immutable
1514
1529
  end
1515
1530
  result.concat(remainder)
1516
1531
  end
1517
- elsif child = node[from_slot]
1532
+ elsif (child = node[from_slot])
1518
1533
  result = node.take(from_slot)
1519
1534
  result.push(replace_node_suffix(child, bitshift - BITS_PER_LEVEL, from, suffix))
1520
1535
  remainder = suffix.shift((31 - from_slot) * (1 << bitshift))
@@ -1,5 +1,5 @@
1
1
  module Immutable
2
2
  # Current released gem version. Note that master will often have the same
3
3
  # value as a release gem but with different code.
4
- VERSION = "0.0.1"
4
+ VERSION = '0.1.0'
5
5
  end
data/lib/immutable.rb CHANGED
@@ -1,9 +1,9 @@
1
- require "immutable/core_ext"
2
- require "immutable/list"
3
- require "immutable/deque"
4
- require "immutable/hash"
5
- require "immutable/set"
6
- require "immutable/vector"
7
- require "immutable/sorted_set"
8
- require "immutable/nested"
9
- require "immutable/version"
1
+ require 'immutable/core_ext'
2
+ require 'immutable/list'
3
+ require 'immutable/deque'
4
+ require 'immutable/hash'
5
+ require 'immutable/set'
6
+ require 'immutable/vector'
7
+ require 'immutable/sorted_set'
8
+ require 'immutable/nested'
9
+ require 'immutable/version'