Created
October 4, 2016 18:52
-
-
Save sdebaun/47b9b5aa4731ec81201d48590d4315ac to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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