How to use the prelude-ts.Vector.ofIterable function in prelude-ts

To help you get started, we’ve selected a few prelude-ts examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github klemola / foobar2000-web-ui / server / Message.ts View on Github external
function parseTrackData(text: string): Result<TrackInfo> {
    const items = Vector.ofIterable(text.split('|'))
    const status = items.head()
    // Get rid of fields that we don't care about
    const otherValues = items.drop(3)

    if (status.isNone() || otherValues.length() < trackInfoKeys.length - 1) {
        return failure('Could not parse track data')
    }

    const values = otherValues.prepend(status.get())
    const trackInfoEntries = Vector.zip(trackInfoKeys, values)
    const trackInfo = HashMap.ofIterable(trackInfoEntries)
        .filterKeys(k => !k.startsWith('unknown'))
        .map((k, v) => [k, mapTrackInfoValue(k, v)])
        .put('state', statusCodeToName(status.get()))
        .toObjectDictionary(x => x)
github klemola / foobar2000-web-ui / server / MockControlServer / index.ts View on Github external
socket.on('data', data => {
        const state = stateWrapper.get()
        const stringData = Vector.ofIterable(data.toString())
            // get rid of CRLF
            .dropRight(2)
            .mkString('')

        if (Action.guard(stringData)) {
            const nextState = stateWrapper.set(update(state, stringData))

            socket.write(
                [
                    mockTrackInfoResponse(nextState.currentTrack),
                    mockVolumeResponse(nextState.currentVolume)
                ].join('\r\n')
            )

            return logger.debug('Received command', {
                action: stringData,
github klemola / foobar2000-web-ui / server / Message.ts View on Github external
function parseMessage(raw: string): Result<Message> {
    const parseMessageFailure: Failure = failure('Could not parse message')
    const messageCode = raw.substring(0, 3)

    switch (statusCodeToName(messageCode)) {
        case 'info':
            return success({
                type: 'info',
                data: raw
            })

        case 'volumeChange':
            const vol = Vector.ofIterable(raw.split('|'))
                .filter(v => v !== '')
                .last()

            return vol.isSome()
                ? success(nextVolume(vol.get()))
                : parseMessageFailure

        case 'playing':
        case 'paused':
        case 'stopped':
            const trackInfo = parseTrackData(raw)
            return trackInfo.success
                ? mapSuccess(trackInfo, (value: TrackInfo) => ({
                      type: 'playback',
                      data: value
                  }))
github klemola / foobar2000-web-ui / server / Message.ts View on Github external
export function parseControlData(text: string): Message[] {
    const lines: string[] = text.split('\r\n')
    const messageList: Vector<Message> = Vector.ofIterable(lines).mapOption(
        l => {
            const messageResult = parseMessage(l)
            return messageResult.success
                ? Option.of(messageResult.value)
                : Option.none()
        }
    )

    if (messageList.allMatch(InfoMessage.guard)) {
        return [
            {
                type: 'info',
                data: messageList.foldLeft(
                    '',
                    (data, message) =>
                        `${data}${data.length === 0 ? '' : '\n'}${message.data}`