ramda / ramda

:ram: Practical functional Javascript

Home Page:https://ramdajs.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

R.aperture returns arbitrary/random ordering of "consecutive" elements

Sieabah opened this issue · comments

I'm trying to do something simple and retrieve a sorted set through Redis with scores and essentially use ramda to join and manpulate the key+score pairs.

The array received from redis is the following

const arr = [
    'socket_018aa22165b7ef0fc55ade169127556d',
    '1694937212412',
    'socket_018aa22136fc53eb681673d54840f571',
    '1694937205410',
    'socket_018aa2211088918b7d891a151863ef6f',
    '1694937195565',
    'socket_018aa220a1884d8edcf847b882fc253e',
    '1694937187157',
    'socket_018aa2207f7976a19e7e093c08806214',
    '1694937158435',
    'socket_018aa2200ee0e602f3d480e8bc5934f2',
    '1694937149618',
    'socket_018aa21fcd2ed6e64b5e27d2f790edad',
    '1694937117790',
    'socket_018aa21faea0da3fb66b4969f261f6e4',
    '1694937104972',
    'socket_018aa21e0116eaff72fce7417af16063',
    '1694937095010',
    'socket_018aa21c43c1b58abf9a9987437492d8',
    '1694936985992',
    'socket_018aa21bc75ac76e9a264f2b2c993e3b',
    '1694936869150',
    'socket_018aa21b8cd8369a163d24243056184c',
    '1694936839181',
    'socket_018aa21ac7a61f36408bc916a28f0bec',
    '1694936823704',
    'socket_018aa2186ebc56c3d979cf1f1492fe54',
    '1694936774851',
    'socket_018aa2165ce3fc3e3ac669bf2546c057',
    '1694936619220',
    'socket_018aa21399c30416f6fdad1b43375b23',
    '1694936483191',
    'socket_018aa2132b42a99681c043b60134aaf5',
    '1694936304910',
    'socket_018aa212e9ba8da49f2609118ef07b27',
    '1694936273134',
    'socket_018aa210bb417b59135dfb62221a060f',
    '1694936260231',
    'socket_018aa210a8ce92c46714097bf8b905fa',
    '1694936115495',
    'socket_018aa210714708efdc3b59f6e5b4269b',
    '1694936111216',
    'socket_018aa20d9eef9bb1e3ac0e44960884e8',
    '1694936096294'
];

Now when trying to get the aperture of this list of size 2 it returns a list of correctly sized lists but the ordering of the sublists seem arbitrary/random? What I see happening is the following:

[ a, b, c, d, e, f, g, h ] -> [ [a, b], [d, c], [f, e], [g, h] ]

Where the first and last elements are correct, but the lists between first and last are arbitrary.

Here is the output from running R.aperture(2, arr)

[
    [
        "socket_018aa22165b7ef0fc55ade169127556d",
        "1694937212412"
    ],
    [
        "1694937212412",
        "socket_018aa22136fc53eb681673d54840f571"
    ],
    [
        "socket_018aa22136fc53eb681673d54840f571",
        "1694937205410"
    ],
    [
        "1694937205410",
        "socket_018aa2211088918b7d891a151863ef6f"
    ],
    [
        "socket_018aa2211088918b7d891a151863ef6f",
        "1694937195565"
    ],
    [
        "1694937195565",
        "socket_018aa220a1884d8edcf847b882fc253e"
    ],
    [
        "socket_018aa220a1884d8edcf847b882fc253e",
        "1694937187157"
    ],
    [
        "1694937187157",
        "socket_018aa2207f7976a19e7e093c08806214"
    ],
    [
        "socket_018aa2207f7976a19e7e093c08806214",
        "1694937158435"
    ],
    [
        "1694937158435",
        "socket_018aa2200ee0e602f3d480e8bc5934f2"
    ],
    [
        "socket_018aa2200ee0e602f3d480e8bc5934f2",
        "1694937149618"
    ],
    [
        "1694937149618",
        "socket_018aa21fcd2ed6e64b5e27d2f790edad"
    ],
    [
        "socket_018aa21fcd2ed6e64b5e27d2f790edad",
        "1694937117790"
    ],
    [
        "1694937117790",
        "socket_018aa21faea0da3fb66b4969f261f6e4"
    ],
    [
        "socket_018aa21faea0da3fb66b4969f261f6e4",
        "1694937104972"
    ],
    [
        "1694937104972",
        "socket_018aa21e0116eaff72fce7417af16063"
    ],
    [
        "socket_018aa21e0116eaff72fce7417af16063",
        "1694937095010"
    ],
    [
        "1694937095010",
        "socket_018aa21c43c1b58abf9a9987437492d8"
    ],
    [
        "socket_018aa21c43c1b58abf9a9987437492d8",
        "1694936985992"
    ],
    [
        "1694936985992",
        "socket_018aa21bc75ac76e9a264f2b2c993e3b"
    ],
    [
        "socket_018aa21bc75ac76e9a264f2b2c993e3b",
        "1694936869150"
    ],
    [
        "1694936869150",
        "socket_018aa21b8cd8369a163d24243056184c"
    ],
    [
        "socket_018aa21b8cd8369a163d24243056184c",
        "1694936839181"
    ],
    [
        "1694936839181",
        "socket_018aa21ac7a61f36408bc916a28f0bec"
    ],
    [
        "socket_018aa21ac7a61f36408bc916a28f0bec",
        "1694936823704"
    ],
    [
        "1694936823704",
        "socket_018aa2186ebc56c3d979cf1f1492fe54"
    ],
    [
        "socket_018aa2186ebc56c3d979cf1f1492fe54",
        "1694936774851"
    ],
    [
        "1694936774851",
        "socket_018aa2165ce3fc3e3ac669bf2546c057"
    ],
    [
        "socket_018aa2165ce3fc3e3ac669bf2546c057",
        "1694936619220"
    ],
    [
        "1694936619220",
        "socket_018aa21399c30416f6fdad1b43375b23"
    ],
    [
        "socket_018aa21399c30416f6fdad1b43375b23",
        "1694936483191"
    ],
    [
        "1694936483191",
        "socket_018aa2132b42a99681c043b60134aaf5"
    ],
    [
        "socket_018aa2132b42a99681c043b60134aaf5",
        "1694936304910"
    ],
    [
        "1694936304910",
        "socket_018aa212e9ba8da49f2609118ef07b27"
    ],
    [
        "socket_018aa212e9ba8da49f2609118ef07b27",
        "1694936273134"
    ],
    [
        "1694936273134",
        "socket_018aa210bb417b59135dfb62221a060f"
    ],
    [
        "socket_018aa210bb417b59135dfb62221a060f",
        "1694936260231"
    ],
    [
        "1694936260231",
        "socket_018aa210a8ce92c46714097bf8b905fa"
    ],
    [
        "socket_018aa210a8ce92c46714097bf8b905fa",
        "1694936115495"
    ],
    [
        "1694936115495",
        "socket_018aa210714708efdc3b59f6e5b4269b"
    ],
    [
        "socket_018aa210714708efdc3b59f6e5b4269b",
        "1694936111216"
    ],
    [
        "1694936111216",
        "socket_018aa20d9eef9bb1e3ac0e44960884e8"
    ],
    [
        "socket_018aa20d9eef9bb1e3ac0e44960884e8",
        "1694936096294"
    ]
]

The ramda repl also has this behavior

I misunderstood aperture's use case, I see it's returning a b, b c, c d, d e

The function I was looking for was splitEvery