我对 elm 还很陌生,并且遇到了使用后端数据填充模型的问题。我目前可以向服务器发出 get 请求,该请求返回一个 byte[] (数据是任何类型的图像、音频或视频),当仅通过 Html.img 显示此数据时,它可以正常工作。当我尝试使用 Http.get (src: https: //package.elm-lang.org/packages/elm/http/latest/Http)来填充我的模型时,它需要解码器。问题是,Bytes.Decode.bytes 需要一个 Int 来知道需要解码多少字节。所以我的问题是:有没有什么方法可以访问字节宽度,同时仍然匹配 Http.get 的类型模式?
这是我的问题的一个简单示例:
import Bytes exposing (Bytes)
import Bytes.Decode exposing (Decoder, bytes, decode)
import GeneralTypes exposing (Msg(..))
import Http
getMediaFromUrl : Cmd Msg
getMediaFromUrl = Http.get
{ url = "http://localhost:8090/image/2006/aa@a.de/session"
, expect = Http.expectBytes GetThumbnail decodeBytes
}
decodeBytes: Bytes.Bytes -> Decoder Bytes
decodeBytes bytesToDecode= let
fileSize =
bytesToDecode |> Bytes.width
in
Bytes.Decode.bytes fileSize
Run Code Online (Sandbox Code Playgroud)
module GeneralTypes exposing (..)
import Bytes exposing (Bytes)
import Http …Run Code Online (Sandbox Code Playgroud) 我想知道是否有办法使用 java 的流 API 过滤连续/互连的元素?
为您提供此问题的背景:我检索了包含不同停靠点的交通线列表。作为用户,我现在只想知道从 X 到 Y 的路线上的旅行时间和站点。所以我需要过滤所有相互连接的路段(停止 a -> 停止 b)。
我有一个未排序的对象列表,其中包含字段start和end。我现在想检索一个列表,该列表仅包含在这两个点之间逻辑连接的元素。这里有一个简单的例子:
我想过滤开始 B和结束 E
List to filter: {A,B},{B,C},{C,D},{D,E},{E,F}
List I want: {B,C},{C,D},{D,E}
Run Code Online (Sandbox Code Playgroud)