These are chat archives for ramda/ramda

17th
Aug 2016
David Langford
@That-David-Guy
Aug 17 2016 04:34
@zeecher I'd do it like this, but it is pretty similar to what you have already
@ram-bot
@ram-bot
const opponents = [
        {
            "id": 35,
            "name": "Ronaldinho"
        },
        {
            "id": 233,
            "name": "Zidane"
        },
        {
            "id": 9772,
            "name": "Messi"
        },
        {
            "id": 78426,
            "name": "Ronaldo"
        },
        {
            "id": 104211,
            "name": "Runey"
        },
        {
            "id": 170654,
            "name": "Fabregas"
        },
        {
            "id": 185602,
            "name": "Mata"
        },
        {
            "id": 185603,
            "name": "Robin"
        }
    ]

const matches = [
    {
        "id": 1122986,
        "opp1": 35,
        "opp2": 233,
        "match_date": 1471327200,
        "match_no": 1,

    },
     {
        "id": 1122986,
        "opp1": 9772,
        "opp2": 78426,
        "match_date": 1471327200,
        "match_no": 2,

    },  
    {
        "id": 1122986,
        "opp1": 104211,
        "opp2": 170654,
        "match_date": 1471327200,
        "match_no": 3,

    },  
    {
        "id": 1122986,
        "opp1": 185602,
        "opp2": 185603,
        "match_date": 1471327200,
        "match_no": 4,

    },
]



const findObjPropByKey = R.curry((key, prop, array, value) => 
 R.prop(prop, R.find(R.propEq(key, value), array)))

const findOpponentName = findObjPropByKey('id', 'name', opponents)

const combineWithOpponent = ({id, match_date, match_no, opp1, opp2}) =>
({
    id: id,
    date: match_date,
    no: match_no,
    opponentOne: findOpponentName(opp1),
    opponentTwo: findOpponentName(opp2)
})

const getMatchAndOpponentDetails = map(combineWithOpponent)


getMatchAndOpponentDetails(matches)
ram-bot
@ram-bot
Aug 17 2016 04:34
Unexpected token {
David Langford
@That-David-Guy
Aug 17 2016 04:35
@ram-bot
const opponents = [
        {
            "id": 35,
            "name": "Ronaldinho"
        },
        {
            "id": 233,
            "name": "Zidane"
        },
        {
            "id": 9772,
            "name": "Messi"
        },
        {
            "id": 78426,
            "name": "Ronaldo"
        },
        {
            "id": 104211,
            "name": "Runey"
        },
        {
            "id": 170654,
            "name": "Fabregas"
        },
        {
            "id": 185602,
            "name": "Mata"
        },
        {
            "id": 185603,
            "name": "Robin"
        }
    ]

const matches = [
    {
        "id": 1122986,
        "opp1": 35,
        "opp2": 233,
        "match_date": 1471327200,
        "match_no": 1,

    },
     {
        "id": 1122986,
        "opp1": 9772,
        "opp2": 78426,
        "match_date": 1471327200,
        "match_no": 2,

    },  
    {
        "id": 1122986,
        "opp1": 104211,
        "opp2": 170654,
        "match_date": 1471327200,
        "match_no": 3,

    },  
    {
        "id": 1122986,
        "opp1": 185602,
        "opp2": 185603,
        "match_date": 1471327200,
        "match_no": 4,

    },
]



const findObjPropByKey = R.curry((key, prop, array, value) => 
 R.prop(prop, R.find(R.propEq(key, value), array)))

const findOpponentName = findObjPropByKey('id', 'name', opponents)

const combineWithOpponent = (match) =>
({
    id: match.id,
    date: match.match_date,
    no: match.match_no,
    opponentOne: findOpponentName(match.opp1),
    opponentTwo: findOpponentName(match.opp2)
})

const getMatchAndOpponentDetails = map(combineWithOpponent)


getMatchAndOpponentDetails(matches)
ram-bot
@ram-bot
Aug 17 2016 04:35
[ { id: 1122986,
    date: 1471327200,
    no: 1,
    opponentOne: 'Ronaldinho',
    opponentTwo: 'Zidane' },
  { id: 1122986,
    date: 1471327200,
    no: 2,
    opponentOne: 'Messi',
    opponentTwo: 'Ronaldo' },
  { id: 1122986,
    date: 1471327200,
    no: 3,
    opponentOne: 'Runey',
    opponentTwo: 'Fabregas' },
  { id: 1122986,
    date: 1471327200,
    no: 4,
    opponentOne: 'Mata',
    opponentTwo: 'Robin' } ]
David Langford
@That-David-Guy
Aug 17 2016 04:35
@ram-bot doesn't like the es6 deconstructor in arugments :(
James Forbes
@JAForbes
Aug 17 2016 06:14

So you know how ap and chain can both replace usages of converge. Is there a similar situation for useWith

E.g.


var f = R.useWith(map, [identity, match(/(\w|'s)+/g)])

f(template, "animal's are great")
//=> ["<span class=\"match\">animal's</span>", "<span class=\"match\">are</span>", "<span class=\"match\">great</span>"]
Scott Christopher
@scott-christopher
Aug 17 2016 07:12
@JAForbes I suspect there is something close to a church-encoded version of first and second in terms of Arrows, but not 100% sure if there is a direct analogue.
@ram-bot
// Tuple a b :: (a -> b -> c) -> c
// tuple :: a -> b -> Tuple a b
const tuple = (a, b) => (t => t(a, b))

const first  = f => t => t((a, c) => tuple(f(a), c))
const second = f => t => t((a, b) => tuple(a, f(b)))

const add5toFst = first(add(5))
const of6and2 = add5toFst(tuple(1, 2))

of6and2(multiply)
ram-bot
@ram-bot
Aug 17 2016 07:12
12
Scott Christopher
@scott-christopher
Aug 17 2016 07:14
looks like an interesting distraction for me to dig a bit deeper :D
zeecher Game
@zeecher
Aug 17 2016 09:34
@That-David-Guy, thank you, for the clean and optimized solution.
James Forbes
@JAForbes
Aug 17 2016 09:40
:D @scott-christopher
Juan Lulkin
@joaomilho
Aug 17 2016 11:19
would love to hear your thoughts https://github.com/act-framework/act
Vladimir Starkov
@iamstarkov
Aug 17 2016 12:01
hi, i was again thinking a bit about testing high-order functions like (curry and pipe) for a while,
what i found out that we can use property-based testing for this purposes
/cc @Bradcomp @rjmk j
Vladimir Starkov
@iamstarkov
Aug 17 2016 15:15
what do you think?
Brad Compton (he/him)
@Bradcomp
Aug 17 2016 15:59
That's a good idea! You have clear properties that should hold for each function:
for all f, g => compose(f, g)(arg) == f(g(arg))
for all f, a, b => curry(f)(a)(b) == f(a, b)
I think the problem is generating random instances of the functions to test with
I wouldn't even know how to start on that problem TBH
@joaomilho That looks cool! I will have to check it out.
Rafe
@rjmk
Aug 17 2016 18:00
@Bradcomp @iamstarkov I think JSVerify comes with arbitraries for functions. (It basically works by randomly generating outputs and keeping a map of already generated outputs to keep it consistent)
Brad Compton (he/him)
@Bradcomp
Aug 17 2016 18:08
@rjmk That is really cool!
It doesn't look like JS Verify is a dev-dependancy f the project. Is there any PBT being done for Ramda yet?
Rick Medina
@rickmed
Aug 17 2016 23:34
@joaomilho do you have a gitter?