These are chat archives for ramda/ramda

1st
Jun 2016
Travis LaDuke
@laduke
Jun 01 2016 02:38
is there a traditional name for something like this: beginsWith([1,2,3,4], [1,2]) //=> true like subset but order matters
Scott Christopher
@scott-christopher
Jun 01 2016 03:34
@laduke If the values need to exist consecutively, it is sometimes referred to as an infix. If they just need to exist somewhere in the larger list in the same order, subsequence is sometimes used.
This message was deleted
@ram-bot
const isPrefix = curry((sub, xs) => {
  if (sub.length === 0) return true
  if (xs.length === 0 || !equals(sub[0], xs[0])) return false
  return isPrefix(tail(sub), tail(xs))
})

const tails = xs => reduceRight((ts, x) => prepend(prepend(x, ts[0]), ts), [[]], xs)

const isInfix = curry((sub, xs) => any(isPrefix(sub), tails(xs)))

isInfix([1, 2], [3, 4, 1, 2, 5, 6])
ram-bot
@ram-bot
Jun 01 2016 03:36
true
Scott Christopher
@scott-christopher
Jun 01 2016 03:37
@ram-bot
const isSubsequence = (sub, xs) => {
  if (sub.length === 0) return true
  if (xs.length === 0) return false
  const [subHead, ...subTail] = sub,
        [xsHead, ...xsTail] = xs
  if (equals(subHead, xsHead)) return isSubsequence(subTail, xsTail)
  return isSubsequence(sub, xsTail)
}

isSubsequence([1, 2], [1, 3, 2, 4])
ram-bot
@ram-bot
Jun 01 2016 03:37
Unexpected token [
Scott Christopher
@scott-christopher
Jun 01 2016 03:38
try again
@ram-bot
const isSubsequence = (sub, xs) => {
  if (sub.length === 0) return true
  if (xs.length === 0) return false
  if (equals(sub[0], xs[0])) return isSubsequence(tail(sub), tail(xs))
  return isSubsequence(sub, tail(xs))
}

isSubsequence([1, 2], [1, 3, 2, 4])
ram-bot
@ram-bot
Jun 01 2016 03:38
true
Travis LaDuke
@laduke
Jun 01 2016 04:21
@scott-christopher thanks!
Travis LaDuke
@laduke
Jun 01 2016 04:28
my naive isPrefix needed those length === 0 checks. Now I can use yours!
Tobias Pflug
@gilligan
Jun 01 2016 07:18
const isPrefixOf = R.invoker(1, 'startsWith');
@laduke ^
Martin Broder
@mrtnbroder
Jun 01 2016 12:27
is there a handy utility function within ramda that allows piping a value through some validators?
pseudo-code: pipe(isNumber, isOver10, isUnder20)(value)
ah! allPass
Martin Broder
@mrtnbroder
Jun 01 2016 12:32
thanks!
xD
Raine Virta
@raine
Jun 01 2016 13:14
s/validators/predicates/
Lewis
@6ewis
Jun 01 2016 13:45
anyone use gulp?
Brad Compton (he/him)
@Bradcomp
Jun 01 2016 15:30
@6ewis I do, but I've pretty much just set it up and forgotten about it. Feel free to PM me if you want though.