These are chat archives for ramda/ramda

14th
Jan 2017
William R. Sousa
@Zutak
Jan 14 2017 03:42
Hello There! How can I find out the type of an expression or a subexpression in Ramda?
does it have the equivalent (from Haskell) ?
:type sum
sum :: (Foldable t, Num a) => t a -> a
Brad Compton (he/him)
@Bradcomp
Jan 14 2017 05:02
R.sum
Brad Compton (he/him)
@Bradcomp
Jan 14 2017 05:03
@Zutak You can type a ramda function in here to get the type info.
Sudarsan Balaji
@artfuldev
Jan 14 2017 10:35
Hi guys,
so remember the last problem?
I attempted a refactor in C# to functional style (with a lot of helpers) and here's what I have
private static int GetNumberOfTransmitters(ints houseLocations, int coverageLength)
{
    var sortUniqueAsList = Compose(Enumerable.ToList, Compose<ints, ints, ints>(Sort, Unique));
    var houses = sortUniqueAsList(houseLocations);
    Func<ints,int,int,int> getNextUncoveredIndex = (locations, coverage, current) =>
    {
        var list = locations.ToList();
        var location = list[current];
        var coverageLimit = location + coverage;
        var coveredLength = list.Skip(current).TakeWhile(x => x <= coverageLimit).Count();
        return coveredLength + current;
    };
    var nextUncoveredHouseIndex = getNextUncoveredIndex.Apply(houses, coverageLength);
    var nextTrasmitterIndex = Compose(Decrement, nextUncoveredHouseIndex);
    var next = Compose(nextUncoveredHouseIndex, nextTrasmitterIndex);
    var initialState = new State {Current = 0, Count = 0};
    var stateEvolver = Evolve(
        EvolutionConfiguration<State>
            .For(s => s.Current, next)
            .AndFor(s => s.Count, Increment));
    return
        ReduceWhile(
            (state, location) => state.Current < houses.Count,
            (state, location) => stateEvolver(state),
            initialState, houses).Count;
}
ints is short for IEnumerable<int>
I haven't used the converge function etc, and I realize I'm converting to a list earlier on and using it.
But other than that, is there anything I can do to make this implementation better?
Sudarsan Balaji
@artfuldev
Jan 14 2017 10:40
stateEvolver(state) actually mutates state. can that be overlooked?
Sudarsan Balaji
@artfuldev
Jan 14 2017 10:48
@galileopy @joneshf @JAForbes if you guys remember
Nakshatra Mukhopadhyay
@n0x3u5
Jan 14 2017 12:13
Hey all!
What is the correct way to import modules from RamdaJS?
The usual import { <module> } from <package> syntax does not seem to work for RamdaJS...
Sudarsan Balaji
@artfuldev
Jan 14 2017 14:03
R.dec
Sudarsan Balaji
@artfuldev
Jan 14 2017 14:18
is the code for this @ram-bot open sourced anywhere?
David Chambers
@davidchambers
Jan 14 2017 15:00
Rick Medina
@rickmed
Jan 14 2017 15:09
hey all! this question is not related to ramda but maybe you could help me out? it's about unit tests. Let's say I have a low level function that needs to be stubbed (http request or something) which is used in the n level deep by other modules, what is a good testing strategy?
hemanth.hm
@hemanth
Jan 14 2017 15:28
@ram-bot source
Alec
@alavkx
Jan 14 2017 16:20
GUYS I NEED HELP

i think it is very basic/lack of understanding but..

(0 , _fp.safeParse) is not a function

pretty sure my composition is bad
mTest = x => x ? Just(x) : Nothing(),

mSet = map(mTest),

// :: String -> [Maybe a]
safeParse = jsonData => compose(mSet, JSON.parse, jsonData)
isStatusOk = x => x.status >= 200 && x.status <= 304,

mOutcome = (reject, resolve, x) =>
  isStatusOk(x) ?
  resolve(safeParse(x.response)) :      // :>D Wooo!
  reject(Error(x.statusText)),                 // D<: Booo!

// :: String -> String -> Future Error [Maybe a]
xhr = (method, url) =>
  Future((reject, resolve) => {
    const unsafeXhr = new XMLHttpRequest();

    unsafeXhr.onload = () => mOutcome(reject, resolve, unsafeXhr);

    unsafeXhr.open(method, url, true /* async enabled */);
    unsafeXhr.send(null);
  });
wrapping xhr with a future, and attempting to parse the json and wrap each element with a maybe
dcmwong
@dcmwong
Jan 14 2017 16:25
@rickmed Hey, as you said this isn’t particularly related to ramada but the answer to your question is dependency injection. If you can expose the http library as a dependency then you’ll find that in your test you’ll be able to mock out the request you are making with the http library
@rickmed In addition, in functional programming, this can be achieved by currying.
Rick Medina
@rickmed
Jan 14 2017 16:45
correct, so basically I need to be aware of all cases when such http library is used within the function (at whatever level deep) to accomodate the test? EG: bar = pipe( foo1, foo2, foo3)... foo2 uses the http lib... when testing bar I need to setup the test input of bar, analyze what would be the output of foo1 so I can stub foo2 correctly?
@dcmwong
(however the DI is solved: by an additional param, currying or not, passing with "this", reader monad, etc)
dcmwong
@dcmwong
Jan 14 2017 16:52
if foo2 is the function fetching data in the test set it up so that it just returns the data you expect. in the actual code you can the foo2 version that uses http
Rick Medina
@rickmed
Jan 14 2017 17:00

@dcmwong

function bar (p) {
  let a = // some logic with using p...
  let b = foo2(a);
  let c = // some logic with using b...
  return c
}

I would need to analyze what "a" returns so I can check that foo2 is called with the correct params, stub foo2 so that is returns some data and analyze what "c" returns so I can set the expected test result?

I'm sure I'm looking at this all wrong...