These are chat archives for ramda/ramda

20th
Feb 2017
Brandon Orther
@orther
Feb 20 2017 00:11
Anyone have an elegant code suggestion for creating a new array with a specific item (indicated by index) moved one position higher or lower? I am using it for moving a UI item up or down in sort order. My 5 line solutions grosses me out 😀
Currently I'm just creating a function that I pass in an array, the index of the item I want moved and +1/-1
Rafi
@Rafi993
Feb 20 2017 00:21
R you looking for something like R.range(1,10)??
Denis Stoyanov
@xgrommx
Feb 20 2017 01:01
This message was deleted
ram-bot
@ram-bot
Feb 20 2017 01:01
Unexpected token [
Denis Stoyanov
@xgrommx
Feb 20 2017 01:02
zip via anamorphism https://goo.gl/FdLDyd
Brian McKenna
@puffnfresh
Feb 20 2017 05:50
@orther array zipper
Bravi
@Bravilogy
Feb 20 2017 11:09
hi guys. this stuff is working but I was wondering what could I improve:
const login = curry((username, password) =>
    Future((reject, resolve) =>
        axios.post('api/users', { username, password })
            .then(resolve).catch(reject))
    .map(compose(Maybe.of, prop('data'))));

const validateUsername = ifElse(test(/^(0|[0-9])*$/g),
    () => Failure(['Bad username']),
    Success);

const validatePassword = ifElse(compose(gt(10), length),
    () => Failure(['Bad password']),
    Success);

const validateForm = (username, password) =>
    Success(login)
        .ap(validateUsername(username))
        .ap(validatePassword(password));

validateForm('Heisenberg', '101jdkaiwj')
    .fold(
        errors =>
            dispatch({
                type: 'VALIDATION_ERROR',
                errors
            }),
        success =>
            success.fork(
                error =>
                    dispatch({
                        type: 'LOGIN_ERROR',
                        error
                    }),
                // mapping over a Maybe here
                map(user =>
                    dispatch({
                        type: 'LOGGED_IN',
                        user
                    }))));
any recommendations / suggestions are welcome :)
I'm using Validation, Maybe and Future
Andrei Nemes
@simplysh
Feb 20 2017 12:07

hi guys, I'm trying to determine whether an element (currently clicked on) is contained within a selector; here is what I have

const $ = R.invoker(1, 'querySelectorAll');
const containsTarget = node => node.contains(target);
return R.any(containsTarget, $('[data-card]')(document));

This works, but I feel there may be a more straightforward way that I'm missing. Is there a better way to do this?

Vincent Orr
@Cmdv
Feb 20 2017 12:14
what is the operator for creating a set of numbers ie: [1..3] == [1,2,3] ?
got it was range(1, 3)
Gabe Johnson
@gabejohnson
Feb 20 2017 13:31

a babel plugin for currying syntax? :thumbsup: / :thumbsdown: ? It would be useful to wrap all native (and user) functions to make compositions more readable

@rickmed I would try a plugin like that out

would you wrap them at the call site?
Rick Medina
@rickmed
Feb 20 2017 13:33
yeap
Gabe Johnson
@gabejohnson
Feb 20 2017 13:34
cool. I might want some directive or pragma for files that use it though
// @curry
...
Rick Medina
@rickmed
Feb 20 2017 13:35
got it
Gabe Johnson
@gabejohnson
Feb 20 2017 13:35
or
use curry’
sweet.js should have language definition features coming in the next few months.
‘lang curry'
Rick Medina
@rickmed
Feb 20 2017 13:37
cool! I just thought of a babel plugin just bc is so widely used
Gabe Johnson
@gabejohnson
Feb 20 2017 13:37
for sure
Rick Medina
@rickmed
Feb 20 2017 13:43
I have no idea what the symbol would be though, I don't think I have seen anything like that in other languages
Gabe Johnson
@gabejohnson
Feb 20 2017 13:44
oh. i didn’t know you were going to use a sigil
i thought you were just going to transform all function calls
Rick Medina
@rickmed
Feb 20 2017 13:44
that could be too
bc maybe there are functions you won't want to be curried... don't know...
Gabe Johnson
@gabejohnson
Feb 20 2017 13:46
right
you’d want to use ASCII chars?
Rick Medina
@rickmed
Feb 20 2017 13:48
not necessarily
Gabe Johnson
@gabejohnson
Feb 20 2017 13:51
λ?
Rick Medina
@rickmed
Feb 20 2017 13:55
wouldn't that be annoying to type?

you’d want to use ASCII chars?

oh I thought you meant single ascii chars

Gabe Johnson
@gabejohnson
Feb 20 2017 13:57
idk. i use a text replace on a mac. lambda -> λ
then .\
anyway, i’d like to see that plugin
Rick Medina
@rickmed
Feb 20 2017 14:01
"%>"?
Gabe Johnson
@gabejohnson
Feb 20 2017 14:07
reminds me of
you could just make up a new keyword
curry
Mick Dekkers
@mickdekkers
Feb 20 2017 14:10
Does anyone have any tips on how I can clean up this code? https://goo.gl/XVgIx0
It's fully functional but could perhaps still use a bit of refactoring
no pun intended :P
Rick Medina
@rickmed
Feb 20 2017 14:21
@gabejohnson I didn't get that reference :) I thought of a keyword but personally I would just use a curry function
Gabe Johnson
@gabejohnson
Feb 20 2017 14:25
@SoullessWaffle https://goo.gl/pklSrT
@rickmed a plugin that curried all the things would be cool. otherwise just using a function really does make the most sense to me
unless you figure out a really cool sigil
Mick Dekkers
@mickdekkers
Feb 20 2017 14:28
@gabejohnson Thanks! That looks a lot better :D
Gabe Johnson
@gabejohnson
Feb 20 2017 14:29
:thumbsup:
@rickmed it was a MAD magazine reference. You’re prbly better off not getting it
Brad Compton (he/him)
@Bradcomp
Feb 20 2017 16:16
:-D
Bravi
@Bravilogy
Feb 20 2017 16:35
I've been experimenting with a few monadic libraries and what I find problematic is that sometimes I need a functionality that is in one library for the same type, to be in the other library that I'm working with and I tend to extend them with prototype. For example data.maybe has orElse method that I like. but Maybe in ramda-fantasy doesn't have that
is there a library that offers a lot?
or should I just keep extending them like this?
Gabe Johnson
@gabejohnson
Feb 20 2017 16:41
@Bravilogy I’ve been looking at https://github.com/evilsoft/crocks for a couple of days
Keith Alexander
@kwijibo
Feb 20 2017 16:47
oh that's cool, I hadn't seen that. Nice.
Bravi
@Bravilogy
Feb 20 2017 16:48
@gabejohnson thanks, this is what I needed :D
I was starting to think about creating one
phew
Keith Alexander
@kwijibo
Feb 20 2017 16:49
@Bravilogy yep this is a problem. If you look in the issues in fantasyland, there is some movement towards trying to coalesce around a single implementation for some simple types
Gabe Johnson
@gabejohnson
Feb 20 2017 16:49
np. I don’t think it’s FL compliant though
Bravi
@Bravilogy
Feb 20 2017 16:49
yayy List is traversable
:D
@kwijibo oh good to know it's not just me
Keith Alexander
@kwijibo
Feb 20 2017 16:51
That's what I like about the static-land proposal - with functions, you don't need all the functionality to be in the same module
Gabe Johnson
@gabejohnson
Feb 20 2017 17:14
@kwijibo just read your blog last night. Really clear explanations/examples
:thumbsup:
Keith Alexander
@kwijibo
Feb 20 2017 17:14
thanks @gabejohnson that's really appreciated
Syaiful Bahri
@syaiful6
Feb 20 2017 17:36
you don't need to extending it through prototype, you can always use function that do orElse for ramda fantasy.
just take the Maybe as last arguments, and it will compose well..
Bravi
@Bravilogy
Feb 20 2017 17:39
yeah that's another option but I'm just saying in general
implementations differ
Syaiful Bahri
@syaiful6
Feb 20 2017 17:48
for example i do use Folktale Task, but i use my own fork function, that just expect any object with fork method. So, i can switch to another.
Brian McKenna
@puffnfresh
Feb 20 2017 22:58
where's the blog post? @kwijibo
Keith Alexander
@kwijibo
Feb 20 2017 22:59
One of these ones I think @puffnfresh https://kwijibo.github.io/
Brian McKenna
@puffnfresh
Feb 20 2017 23:03
ah thanks :heart:
Jonah
@jonahx
Feb 20 2017 23:05
here’s a ramda micro-optimization problem… I have a bunch of keys. I want an object with those keys, where each key’s value is just an empty stream. can i improve the following:
  const rawInputs = pipe(map(k => [k, stream('')]), fromPairs)(keys);