Skip to content

Instantly share code, notes, and snippets.

let strings = vec!["7", "42", "one"];
let numbers: Result<Vec<_>,_> = string
.into_iter()
.map(|s| s.parse::<i32>())
.collect::<Result<Vec<_>,_>>();
use beau_collector::BeauCollector as _;
let strings = vec!["7", "42", "one"];
let numbers = string
.into_iter()
.map(|s| s.parse::<i32>())
.bcollect::<Vec<_>>()?;
module Lib
( tot_1
, tot_2
) where
f :: Integral a => a -> a
f x = x `div` 3 - 2
tot_1 :: Integral a => [a] -> a
tot_1 = tot f
module Main where
import Lib
import Data.List
main :: IO ()
main = do
contents <- readFile "inputs.txt"
let inputs = fmap read . lines $ contents
print . Lib.tot_1 $ inputs
fn fold1<F>(self, f: F) -> Option<Self::Item> where
F: FnMut(Self::Item, Self::Item) -> Self::Item,
Self: Sized,
foldFunction :: (a -> b -> Maybe a) -> Maybe a -> b -> Maybe a
foldFunction _ Nothing _ = Nothing
foldFunction f (Just acc) x = f acc x
foldFunction' :: (a -> c -> Either a b) -> Either a b -> c -> Either a b
foldFunction' _ Left x _ = Left x
foldFunction' f (Right acc) x = f acc x
foldl1 :: Foldable t => (a -> a -> a) -> t a -> a