Skip to content

Instantly share code, notes, and snippets.

@briancordanyoung
briancordanyoung / Array+concurrentMap.swift
Last active March 1, 2025 13:49
Execute a throwing task for each element of the array
// MARK: Transform an array of items
extension Array where Element: Sendable {
/// Execute a throwing task for each element of the array.
///
/// - All tasks are executed concurrently,
/// - If the transformer is `nonisolated` all tasks are executed in parallel .
/// - The resulting array maintains the same order as the original array.
/// - If any task throws any error, all tasks are allowed to complete. The resulting error includes a array of
/// results where successful elements can be used and failed elements can be handled.
///
//: Playground - noun: a place where people can play
import Cocoa
// Generate the appropriate integer value for each character using
// a the ascii value from the return unicodeScalars.
// UInt8 (Unsigned 8 bit Integer)
// a | A = 1
// z | Z = 26
// all others will be 0
extension Character {
@briancordanyoung
briancordanyoung / gist:49bf65bd40ba995c9f1f9dd799ad5f68
Last active May 4, 2018 00:15
Rough code for to count the 100 point words
import Cocoa
// a = 97
// z = 122
let value = UInt8(ascii: "z")
extension Character {
var testValues: UInt8? {
@briancordanyoung
briancordanyoung / gist:3148d079b87f8b7ba65cf11c14d9d014
Last active May 4, 2018 00:16
Rough, get values of characters
import Cocoa
// a = 97
// z = 122
let value = UInt8(ascii: "z")
extension Character {
var testValues: UInt8? {
import Foundation
extension Array where Element: Hashable {
/// Returns most popular member of the array
///
/// - SeeAlso: https://en.wikipedia.org/wiki/Mode_(statistics)
///
typealias ArrayMode = (item: Element?, count: Int)
func mode() -> (item: Element?, count: Int) {