How to use prelude-ts - 10 common examples

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 {
    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 / Message.ts View on Github external
function parseTrackData(text: string): Result {
    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)

    return TrackInfo.validate(trackInfo)
}
github klemola / foobar2000-web-ui / server / Message.ts View on Github external
function parseTrackData(text: string): Result {
    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)

    return TrackInfo.validate(trackInfo)
}
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 / ui / App.tsx View on Github external
Volume as VolumeType,
    Action
} from '../server/Models'
import Playback from './Playback'
import Volume from './Volume'

// TODO: refactor into an union type
interface AppState {
    connected: boolean
    currentTrack: Option
    volume: VolumeType
}

const initialState: AppState = {
    connected: false,
    currentTrack: Option.none(),
    volume: {
        type: 'audible',
        volume: 0
    }
}

export default class App extends Component<{}, AppState> {
    socket = io('/', {
        autoConnect: false
    })
    state = initialState

    componentDidMount() {
        this.socket.on('message', (message: Message) => {
            switch (message.type) {
                case 'playback':
github klemola / foobar2000-web-ui / server / Message.ts View on Github external
function parseMessage(raw: string): Result {
    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 = 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}`
github klemola / foobar2000-web-ui / server / Message.ts View on Github external
l => {
            const messageResult = parseMessage(l)
            return messageResult.success
                ? Option.of(messageResult.value)
                : Option.none()
        }
    )
github klemola / foobar2000-web-ui / server / Message.ts View on Github external
l => {
            const messageResult = parseMessage(l)
            return messageResult.success
                ? Option.of(messageResult.value)
                : Option.none()
        }
    )
github klemola / foobar2000-web-ui / ui / App.tsx View on Github external
this.socket.on('message', (message: Message) => {
            switch (message.type) {
                case 'playback':
                    return this.setState({
                        currentTrack: Option.of(message.data)
                    })
                case 'volume':
                    return this.setState({
                        volume: message.data
                    })
            }
        })
        this.socket.on('connect', () => this.setState({ connected: true }))

prelude-ts

A typescript functional programming library

ISC
Latest version published 1 year ago

Package Health Score

49 / 100
Full package analysis