These are chat archives for ramda/ramda

Jan 2017
William R. Sousa
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)
Jan 14 2017 05:02
Brad Compton (he/him)
Jan 14 2017 05:03
@Zutak You can type a ramda function in here to get the type info.
Sudarsan Balaji
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(
            .For(s => s.Current, next)
            .AndFor(s => s.Count, Increment));
            (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
Jan 14 2017 10:40
stateEvolver(state) actually mutates state. can that be overlooked?
Sudarsan Balaji
Jan 14 2017 10:48
@galileopy @joneshf @JAForbes if you guys remember
Nakshatra Mukhopadhyay
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
Jan 14 2017 14:03
Sudarsan Balaji
Jan 14 2017 14:18
is the code for this @ram-bot open sourced anywhere?
David Chambers
Jan 14 2017 15:00
Rick Medina
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?
Jan 14 2017 15:28
@ram-bot source
Jan 14 2017 16:20

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);, url, true /* async enabled */);
wrapping xhr with a future, and attempting to parse the json and wrap each element with a maybe
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
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?
(however the DI is solved: by an additional param, currying or not, passing with "this", reader monad, etc)
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
Jan 14 2017 17:00


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...