Skip to main content
On this pageOverview

Task

Overview

Foldkit provides utility functions for common side effects that return commands you can use in your update function.

Task.getTime gets the current UTC time. Task.getZonedTime gets time with the system timezone. Task.getZonedTimeIn gets time in a specific timezone.

import { Effect } from 'effect'
import { Task } from 'foldkit'

const getTime = Task.getTime.pipe(Effect.map(utc => GotTime({ utc })))

const getZonedTime = Task.getZonedTime.pipe(
  Effect.map(zoned => GotZonedTime({ zoned })),
)

const getNyTime = Task.getZonedTimeIn('America/New_York').pipe(
  Effect.map(zoned => GotNyTime({ zoned })),
  Effect.catchAll(() => Effect.succeed(FailedTimeZone())),
)

Task.focus focuses an element by CSS selector (useful after form submission). Task.randomInt generates random integers.

import { Effect } from 'effect'
import { Task } from 'foldkit'

// Focus an element after form submission
const focusEmailInput = Task.focus('#email-input').pipe(
  Effect.ignore,
  Effect.as(Focused()),
)

// Generate a random integer between 1 and 6 (dice roll)
const rollDice = Task.randomInt(1, 7).pipe(
  Effect.map(value => GotDiceRoll({ value })),
)