Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

For me, the second variant with map chaining

  const dataForTemplate = notificationData
    .map(addReadableDate)
    .map(sanitizeMessage)
    .map(buildLinkToSender)
    .map(buildLinkToSource)
    .map(addIcon);

is the best one, it has way less mental overhead comparing with the end result.

Also a catch with no error handling

  try {
    return Just(JSON.parse(data));
  } catch () {
    return Nothing();
  }
in most cases is not the best idea, at least I'd put a log about it

Nevertheless, waiting for the book from the author

UPD: edited code formatting



It's not performant though generally speaking you keep boxing and unboxing the type (imagine having a list of 100,000 notifications and then mapping over it 5 times in a row). The composition law would give you a just-as-readable option

    const dataForTemplate = notificationData.map(pipe(
      addReadableDate,
      sanitizeMessage,
      buildLinkToSender,
      buildLinkToSource,
      addIcon
    ))

> in most cases is not the best idea, at least I'd put a log about it

Well, in FP you don't want to do side effects like write to console. Instead you want to hold onto the errors (with an `data Either e a = Left e | Right a` instead of `data Maybe a = Just a | Nothing`) til you get to the part of your application where you do do the side effects.

  try {
    return Right(JSON.parse(data))
  } catch (err) {
    return Left(err)
  }




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: