import * as tsplus_module_1 from "@tsplus/stdlib/data/Maybe/definition";
import * as tsplus_module_2 from "@effect/core/stm/STM/operations/fail";
import * as tsplus_module_3 from "@effect/core/stm/STM/operations/succeedNow";
import * as tsplus_module_4 from "@effect/core/stm/STM/operations/foldSTM";
/**
 * Returns a successful effect with the head of the list if the list is
 * non-empty or fails with the error `None` if the list is empty.
 *
 * @tsplus getter ets/STM head
 */

export function head(self) {
  return tsplus_module_4.foldSTM_(self, x => tsplus_module_2.fail(() => tsplus_module_1.some(x)), x => {
    const it = x[Symbol.iterator]();
    const next = it.next();
    return next.done ? tsplus_module_2.fail(() => tsplus_module_1.none) : tsplus_module_3.succeedNow(next.value);
  });
}
//# sourceMappingURL=head.mjs.map