Creating a list of rules from a list of integers
corey979 already gave the standard solution in the comments:
Rule @@@ Partition[{1, 2, 3, 4}, 2, 1]
{1 -> 2, 2 -> 3, 3 -> 4}
But this is also doable with rules like you tried. I'd do it like this:
{1, 2, 3, 4} //. {
{a___, x_Integer, y_Integer, b___} :> {a, x -> y, y, b},
{rules___Rule, _Integer} :> {rules}
}
{1 -> 2, 2 -> 3, 3 -> 4}
BlockMap
:
BlockMap[Apply@Rule, Range@4, 2, 1]
(* {1 -> 2, 2 -> 3, 3 -> 4} *)
Using Through
, which I'm always looking for a reason to use, and rarely find one:
(Most -> Rest)@{1, 2, 3, 4} // Through // Thread
(* {1 -> 2, 2 -> 3, 3 -> 4} *)