Tuesday, April 6, 2021

April 2021 1HaskellADay 1Liners Problems and Solutions

  • 2021-04-07, Wednesday:
    you have (Maybe a, Maybe b)
    you want Maybe (a, b)

    If either (Maybe a) or (Maybe b) is Nothing
    then the answer is Nothing.

    If both (Maybe a) and (Maybe b) are (Just ...)
    then the answer is Just (a, b)

    WHAT SAY YOU?

    • Jérôme Avoustin @JeromeAvoustin: bisequence
    • p h z @phaazon_ with base: uncurry $ liftA2 (,)
    • greg nwosu @buddhistfist: (,) <$> ma <*> mb

Thursday, April 1, 2021

April 2021 1HaskellADay Problems and Solutions

Tuesday, March 23, 2021

March 2021 1HaskellADay 1Liners

  • 2021-03-23:

    You have [a] and (a -> IO b).

    You want IO [(a, b)]

    That is, you want to pair your inputs to their outputs for further processing in the IO-domain.

    • Chris Martin @chris__martin:

      \as f -> traverse @ [] @ IO (\a -> f a >>= \b ->

      return (a, b)) as

    • cλementd Children crossing @clementd:

      traverse (sequenceA . id &&& f)

      (actually, tranverse (sequence . (id &&& f)))

      Or p traverse (traverse f . dup)

  • 2021-03-23: You have

    [([a], [b])]

    You want ([a], [b])

    so: [([1,2], ["hi"]), ([3,4], ["bye"])]

    becomes ([1,2,3,4],["hi","bye"])

    • karakfa @karakfa:

      conc xs = (concatMap fst xs, concatMap snd xs)

Monday, March 1, 2021

March 2021 1HaskellADay Problems and Solutions

Monday, February 1, 2021

February 2021 1HaskellADay Problems and Solutions

Thursday, January 21, 2021

January 2021 1HaskellADay 1Liners

  • 2021-01-28: Opposite problem:
    You have: [(a, Set b)]
    you want: [(a, b)]
    e.g.:  [("hi", fromList [1,2,3]), ("bye", fromList [4,6,7]) ->
    [("hi",1),("hi",2),("hi",3),("bye",4),("bye",6),("bye",7)]
    Interestingly, Set is not a Monad. wut. How do you get around that problem?
    • D Oisín Kidney @oisdk (>>= traverse toList)
    • mine: concatMap (sequence . second Set.toList)
  • 2021-01-28: 
    We have [(Set a, b)]
    we want [(a, b)] 
    where each element of Set a is paired with b, e.g.:
    [(fromList [1,2,3], 'a'), (fromList [4,5,6], 'b')]
    becomes
    [(1,'a'),(2,'a'),(3,'a'),(4,'b'),(5,'b'),(6,'b')]
    • Steve "wash your hands" Trout @strout:
      concatMap (uncurry (liftA2 (,)) . bimap toList pure)
    • insatiable mask wearer @tim_1729
      [(a,b) | (s,b) <- xs, a <- (toList s)]
  • Today, 2021/01/21, is:
    1. Can be written with only 3 digits, What other dates can be so written? Also:
    2. a day where the month and day are NOT amalgamation the year. But which dates are amalgamations?

Wednesday, January 20, 2021

January 2021 1HaskellADay Problems and Solutions