Skip to content

Instantly share code, notes, and snippets.

@sdebaun
Created October 4, 2016 18:52
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save sdebaun/47b9b5aa4731ec81201d48590d4315ac to your computer and use it in GitHub Desktop.
import {
split, pipe, converge, slice, unfold, pair, append, splitAt,
lte, ifElse, length, concat,
prop, over, lensProp,
F,
} from 'ramda'
import {_BOL, _EOL} from './util'
const toTokens = pipe(split(' '), append(_EOL), concat([_BOL, _BOL, _BOL]))
const atLeastFour = pipe(length, lte(4))
const headlessTokens = slice(1, Infinity)
const nextCAW = pipe(slice(0,4), splitAt(-1))
const nextAndRest = converge(pair, [nextCAW, headlessTokens])
const tokensToCAWs = unfold(ifElse(atLeastFour, nextAndRest, F))
export const sentenceToLinks = pipe(toTokens, tokensToCAWs)
export default ({message$}) => ({
parsed$: message$
.filter(prop('text'))
.map(over(lensProp('text'), sentenceToLinks))
.multicast(),
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment